Is a type not serializable because it is not public?

I have an open class that will not serialize correctly. When you try, the following exception is thrown:

The data contract type "MyProject.MyClass" is not serializable because it is not publicly available. A publication of this type will be fixed. In addition, you can make it internal and use the InternalsVisibleToAttribute attribute on your assembly to allow serialization of internal elements - see the documentation for more details. Keep in mind that this has certain security implications.

My class is publicly available though:

[DataContract]
public class MyClass
{
    [DataMember]
    public string Name { get; set; }

    [DataMember]
    private int Count;

    public MyClass()
    {
        Name = string.Empty;
        Count = 0;
    }
}

Why do I get this exception when the class is explicitly open?

+5
2

Windows Phone 7 :

, , WP7 " " " " -land, DataContractSerializer . , .NET, , - , , , , , " ". , , . http://geekswithblogs.net/mikebmcl/archive/2010/12/29/datacontractserializer-type-is-not-serializable-because-it-is-not-public.aspx

, , .

+8

, , . XML .

, :

  • DataMember Count
  • Count
  • IXmlSerializable ( , ),
+2

All Articles