I have the following WCF DataContract:
[DataContract]
public class Occupant
{
private string _Name;
private string _Email;
private string _Organi
Try adding an empty constructor. Often times that will set off the serializer.
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).]
You need a default parameterless constructor. I don't ever plan to actually use mine, so I added a summary for IntelliSense and throw a run-time exception to keep it from being used.
/// <summary>
/// parameterless default constructor only for serialization
/// </summary>
public MyClass() { throw new NotImplementedException("parameterless default constructor only for serialization"); }
My guess would be because _Email
is not initialized. You could set EmitDefaultValue to false
and see if that helps:
[DataMember(EmitDefaultValue = false)]
public string Email
{
When you have NO setter by default, do these steps:
This helps me.
You should add an empty parameter constructor to your datacontract class