What is Sgen.exe and how is it used?

Sgen.exe is a tool that is provided with Visual Studio and can be used to optimize XML serialization.  When used directly, XmlSerializer will create a serialization assembly at run-time for serializing and deserializing the generated code.  It relies heavily on reflection and has the potential to perform very poorly given the size of some IEPDs.  Sgen.exe can be used to create a serialization DLL from an existing DLL that contains the generated classes so that they are not created at runtime.  To use Sgen.exe, call it from the command line with the name of the DLL that contains the generated XML serialization classes as an input argument.


     Example: > sgen.exe MyNiemIepdXmlPersistence.dll

This will generate an XmlSerializers DLL called MyNiemIepdXmlPersistence.XmlSerializers.dll with namespace Microsoft.Xml.Serialization.GeneratedAssembly with a number of type serializers that should be used instead of the default System.Xml.Serialization.XmlSerializer class.

Source: IJIS Technical Advisory Committee NIEM FAQ Series "NIEM IEPD XML Code Generation in C# with .NET 3.5"; see article ID# 547