1

I've read that assembly serialization (sgen.exe) can improve performance. What exactly is providing the improvement? Is it metadata on the Types? I would have thought this would be available through reflection! so why is it required in a separate assembly?

starblue
  • 55,348
  • 14
  • 97
  • 151
learnerplates
  • 4,257
  • 5
  • 33
  • 42
  • possible duplicate of [Serialization Assembly. Is it needed or not?](http://stackoverflow.com/questions/926919/serialization-assembly-is-it-needed-or-not) – stuartd Jul 06 '10 at 09:51
  • 2
    Is it **Assembly Serialization** or a **Serialization Assembly** (eg.: Sgen.exe)? – Jaroslav Jandek Jul 06 '10 at 09:54

1 Answers1

2

The serialization assemblies Data.XmlSerializers.dll which improve the performance of clients that use XML Web service proxies to communicate with servers is described under http://msdn.microsoft.com/en-us/library/bk3w6240.aspx.

If you don't do this the same work will be done at the first usage of XmlSerializer. In the blog Link is described additional setting in <system.diagnostics> area of the application.config file to see more what do XmlSerializer in the background.

In Visual Studio there are a spetion setting in the "Build" tab of project settings (see http://www.eggheadcafe.com/tutorials/aspnet/8eb0e68f-5496-4363-9cb9-dd68447ba187/xml-serializer-generator.aspx). So you not really need to use sgen.exe manually.

To more understand what sgen.exe do you can load an open source version of sgen.exe: xgenplus http://xgenplus.codeplex.com/.

I recommend you aslo to read SGEN XMLSerializer - should be .XMLSerializers.dll added as a reference to the current project or to the GAC?.

If you search in google for XmlSerializer and sgen you will find all the information and even more on the first page of the serch results.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Oleg, thanks for the detailed response, unfortunately it doesn't answer my question, I'm not asking what serialization is but why is it how does serializing your assembly improve performance? The context is a desktop application and not web. How is a pre serialization assembly improving the clr performance? Thanks. – learnerplates Jul 07 '10 at 10:09
  • In links which I posted you can read that the implementation of `XmlSerializer` need such kind of assembly. At the first use of `XmlSerializer` it verify if the assembly not exist it create it in the TEMP directory. This takes much time. If `XmlSerializer` find a pre-created assembly it use it and your program works quickly. Are you agree? – Oleg Jul 07 '10 at 10:23
  • The article isn't clear "When you use an XmlSerializer, a helper assembly(1) with a custom type for serializing your type is created. The C# CodeDom is used to generate this code, which then is compiled by the C# compiler. The runtime must then load this generated assembly, and JIT the code. .........." Does this mean that the CLR always uses the XMLSerializer when loading assemblies? and then the steps mentioned above occur. If so that's what I'm looking for. the CLR tries to serialize the assembly being loaded, if one already exists then it uses that serialized assembly instead. – learnerplates Jul 07 '10 at 10:57
  • I think that you correct understand now. Your program will either use assemblies which you created with respect of sgen.exe of a project settings or your your program will do the same work (generate the corresponding assembly in %TEMP% directory and then use it) dynamically. You use all time "to serialize the assembly" which is wrong. Correct is "serialization assembly", but these are only words. Important only to understand how your program, which used `XmlSerializer`, really works. – Oleg Jul 07 '10 at 11:23
  • lovely Oleg. That's what I was looking for. Cheers. – learnerplates Jul 07 '10 at 12:19