Serialization breaks in .NET 4.5

In 4.5, the implementation of XmlSerializer was replaced with one that isn't dependent on the C# compiler. While it provides better startup performance and stability, you might be running into a compatibility issue between the implementations. Can you try adding the following to your app.config file and see if that fixes the issue?

<configuration>
  <system.xml.serialization>
    <xmlSerializer useLegacySerializerGeneration="true"/>
  </system.xml.serialization>
</configuration>

If you're concerned about having this work on 4.0, you could try detecting the version of the framework at runtime, and dynamically change the configuration if the runtime is 4.5 or higher. I wrote a blog post a while back explaining how to do that:

http://blogs.msdn.com/b/youssefm/archive/2010/01/21/how-to-change-net-configuration-files-at-runtime-including-for-wcf.aspx


We're looking to address this issue in upcoming .NET Framework 4.5 Update. I'll update the post with the download link as soon as update is released. Please contact netfx45compat at Microsoft dot com if you have mission critical app that's impacted, and fix is required urgently. I can help direct you to Microsoft support that can help with your request.


I had a also such a serialization failure. In my case it was caused by a type mismatch of the [DefaultValue(..)] attributes. I had an attached default value of "1.0d" (a double) for a property of type decimal. It seems that the new implementation of the XmlSerializer can't convert such values anymore but the old one could. There is also the option to switch back to the old version of XmlSerializer by adding an attribute in 'App.config' but this is not recommended by Microsoft (and me). Hope this helps someone.