I have a smart client application communicating with its server via WCF. Data is created on the client and then sent over the service to be persisted. The server and client use
Either use full properties with [Serializable]
, or use [DataContract]
and [DataMember]
.
The following was giving me an error, probably because .Net was creating a backing variable under the hood, with some character that the XmlSerializer
didn't like.
[Serializable]
public class MyClass
{
public int MyValue { get; private set; }
...
}
Either create full properties
[Serializable]
public class MyClass
{
int _myValue;
public int MyValue
{
get { return _myValue; }
private set { _myValue = value; }
}
...
}
Or use the DataContract
and DataMember
attributes
[DataContract]
public class MyClass
{
[DataMember]
public int MyValue { get; private set; }
...
}