I am working on a project which generates an assembly. I just noticed that an additional assembly *.XmlSerializers.dll is being generated. Why this file is auto generated and what it is used for?
-
I think you already know why it is generated. if not, it is generated because your project is exposing a kind of webservice. it is always generated either during compile time or during runtime. in runtime it is generated in Temp folder with a random name – AaA Jan 26 '17 at 03:57
5 Answers
In .NET implementation, the XmlSerializer generates a temporary assembly for serializing/deserializing your classes (for performance reasons). It can either be generated on the fly (but it takes time on every execution), or it can be pregenerated during compilation and saved in this assembly you are asking about.
You can change this behaviour in project options (tab Compile -> Advanced Compile Options -> Generate serialization assemblies, Auto or On, respectively). The corresponding element in the project file is GenerateSerializationAssemblies, for example, <GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
.

- 30,738
- 21
- 105
- 131

- 35,875
- 47
- 158
- 240
-
22If it's generated when the project setting is Auto, does that mean it's needed? what happens if you don't deploy the X.XMLSerializers.dll with the application, will it be generated on the fly? – Rory Jul 10 '10 at 17:36
-
4
-
1@Rory, I know this question is old, but that seems to be the case. Three of my projects were set to `Auto`, but only one created a serialization DLL. – ps2goat Jun 18 '15 at 16:33
-
5`**Generate Serialization Assemblies** Specifies whether the compiler will use the XML Serializer Generator Tool (Sgen.exe) to create XML serialization assemblies. Serialization assemblies can improve the startup performance of XmlSerializer if you have used that class to serialize types in your code. By default, this option is set to Auto, which specifies that serialization assemblies be generated only if you have used XmlSerializer to encode types in your code to XML.` https://msdn.microsoft.com/en-us/library/kb4wyys2.aspx – ps2goat Jun 18 '15 at 16:36
-
3VS2015 manual change: right click on project name -> _Properties_ -> _Build_ -> (Scroll down) Generate serialization assembly. – Eido95 Aug 21 '16 at 17:58
FYI. The exact steps to stop the XmlSerializers.dll from being auto-generated are:
- In VS, right-click your project file and select "Properties"
- Click the "Build" tab
- Change the "Generate serialization assembly" dropdown from "Auto" to "Off"
- Rebuild and it will be gone

- 847
- 1
- 8
- 10
-
18
-
1I know this is an old response but in VS2015 Update 3 on a Winforms app targeting .NET 2.0 x86 when compiled on a Win10 Ent 64bit system then even when the setting "Generate serialization assembly" dropdown to "Off" then the *.XmlSerializers.dll is still generated. My app does reference a ASMX web service. Maybe a bug in VS2015 Update 3? – Peter Mar 28 '17 at 13:44
I think this is the JIT (Just in time) compilation of XML serialisers for performance reasons.
You get the same thing with RegEx instances using the RegexOptions.Compiled option turned on.
I'm no .NET CLR expert, sorry for lack of precise technical detail.

- 817
- 6
- 11
*.XmlSerializers.dll
are generated using the Sgen.exe [XML Serializer Generator Tool]
See Sgen.exe on MSDN
Typically the Sgen.exe
is used in Post Build events of Projects. See if your project has a post build event which generates the *.XmlSerializers.dll

- 5,605
- 3
- 36
- 59
The project only generates the project.XMLSerialisers.dll for web applications. For other applications you have to run sgen separately.

- 1,239
- 1
- 14
- 25
-
1My WinForms app generates MyProject.XMLSerializers.dll when the setting it on or auto – Kevin Driedger Feb 15 '17 at 17:11