Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to change the Generate Serialization Assembly value?

I have a client winform application that connects to the local network server of WCF. There has a performance issue on the client side and I searched for the solution and found this post.

It says there that:

This sounds like the serialization assemblies being created at runtime. Try changing the settings of the Serialization Assembly dropdown at the bottom of the Build pane of the properties window for the project.

My question is When to change the Generate Serialization Assembly value and what value should I change it into to improve the performance of my client side application?

My codes is in C#, framework 4, build in VS2010Pro.

like image 240
John Isaiah Carmona Avatar asked Feb 08 '12 02:02

John Isaiah Carmona


People also ask

What does generate serialization Assembly do?

The serialization assembly improves the startup performance of a XmlSerializer when it serializes or deserializes objects of the specified types.


1 Answers

In order to serialize classes/structs, serialization assemblies need to be generated. This can happen at compiletime or runtime. Sgen.exe is used to generate serialization assemblies at compiletime; Visual Studio can optionally automate this process, as you have discovered.

  • Off: Default for Debug configurations (thanks, @Alexandru Lache). Do not generate serialization assemblies at compiletime. Serialization assemblies will be generated each time the application runs, according to MSDN:

    When the XML Serializer Generator is not used, a XmlSerializer generates serialization code and a serialization assembly for each type every time an application is run. To improve the performance of XML serialization startup, use the Sgen.exe tool to generate those assemblies the assemblies in advance. These assemblies can then be deployed with the application.

  • On: Use Sgen.exe to generate a serialization assembly at compiletime. This saves startup time, but increases deployment size.
  • Auto: Default for Release configurations. Officially, only generates assembly if XmlSerializer is used in your code, per MSDN (thanks, @L-Three). In my tests, this didn't always work, so I recommend explicitly setting it to On if you are using XmlSerializer.

So, my answer would be this: if you are concerned about startup time, and you use the Serializable attribute even once, set the option to On. If you are more concerned about deployment size, change it to Off. I never leave it on Auto anymore, because I don't trust it. Like I said, it seems to be the same as Off, but I wouldn't count on it.

Edit: I'm definitely having some trouble differentiating between Off and Auto. The difference isn't clearly defined anywhere. I'd stick with On if you use the Serializable attribute at all, and Off if you don't. I wouldn't take deployment size or startup time into account. I just seem to run into fewer serialization-related bugs if I stick to that rule.

Update:

After a review of the sources mentioned, I believe "startup" refers to the first time an XmlSerializer is used on any given type, not initial application launch. I can't be sure; it's a bit ambiguous.

like image 84
Zenexer Avatar answered Oct 18 '22 19:10

Zenexer