InvalidOperationException with the XmlSerializer in .Net 4.0

There is a small change in the XmlSerializer type that might break your code then moving to .net 4.0. MSDN says: “In the  the XmlSerializer class no longer serializes objects that are marked as [Obsolete].”. Not only is this not grammatically ok, this means: if you have objects in your entities that are marked as obsolete, they cannot be serialized to xml any more.


The simple reason: if you have an old serialized entity with an enum value that is obsolete, you can’t even load it. The error message will tell you that the value of {some enum member name} is not a valid value for that type; so you will need to write “cleanup code” while serializing / deserializing entities to be able to use the entities in serialization again – you have to implement IXmlSerializable in order to get that working.

This also means that the “Obsolete” attribute is no longer a “hint” – it does have impact to the execution of your code and may break existing code.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Sylvio's Infobox

Aktuelle Themen rund um SQL Server, BI, Windows, ...

Meredith Lewis

Professional Digital Portfolio

Vittorio Bertocci

Just another weblog

ScottGu's Blog

Just another weblog

AJ's blog

Thoughts and informations I think worthwhile to share...

Outlawtrail - .NET Development

Architecture & Design

SDX eXperts Flurfunk

Just another weblog

%d bloggers like this: