“Type not expected”, using DataContractSerializer – but it’s just a simple class, no funny stuff?

The exception that is being reported is for VDB_Sync.Model.Konstant. This means that somewhere further up the chain, this class is being pulled into another class and that class is the one being serialized.

The issue is that depending on how Konstant is embedded in this class (for example, if it is in a collection or a generic list), the DataContractSerializer may not be prepared for its appearance during deserialization.

To resolve this, you need to apply the known-type attribute to the class that contains Konstant. Based on your serialization code, I suspect that this is VDB_SessionController.

So, try decorating this class with the KnownType attribute:

[KnownType(typeof(VDB_Sync.Model.Konstant)]
public class VDB_SessionController

Leave a Comment