I have a public class that won't serialize properly. When attempted, the following exception is thrown:
The data contract type 'MyProject.MyClass' is not serializable because it is not public. Making the type public will fix this error. Alternatively, you can make it internal, and use the InternalsVisibleToAttribute attribute on your assembly in order to enable serialization of internal members - see documentation for more details. Be aware that doing so has certain security implications.
My class is public, though:
[DataContract]
public class MyClass
{
[DataMember]
public string Name { get; set; }
[DataMember]
private int Count;
public MyClass()
{
Name = string.Empty;
Count = 0;
}
}
Why am I getting this exception when the class is clearly public?