Datacontract exception. Cannot be serialized

Because you have provided one or more initializing constructors, you will also need to add a parameterless (default) constructor.

i.e. You need to add:

[DataContract]
public class Occupant
{
    // *** Needed only for Serialization
    public Occupant() {}
    ...

This is because the default constructor disappears when you add an explicit constructor.

[The issue isn’t with the method returning List<Occupant>, since methods aren’t serialized).]

Leave a Comment

error code: 521