KnownTypeAttribute serialization error

It can happen that you get this exception while deserializing an object from xml:

Type ‘xxxx’ with data contract name ‘xxxxxxxxx’ is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types – for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.”

Do not despair, this is because the framework need to know what types are nested within the document and what to expect. To fix it, add the KnownType attribute above the unknown class :

[KnownType(typeof(selectionbox))]
public partial class selectionbox
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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