0

I have a number of internal classes in a library DLL that I'm creating. These classes have access via some public methods. A sample internal class is;

internal class MyClass
{
    internal int Id {get;set;}
    internal string Name {get;set;}
}

I need to serialise the object before being returned to the public method. I'm trying to use the XmlSerialise method like

System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(MyObject.GetType());

But when I try this I get the error

Error Inaccessible due to its protection level. Only public types can be processed

How can I overcome this problem, because I want to keep these internal classes private within the library DLL, and they can only be access using the public methods.

neildt
  • 5,101
  • 10
  • 56
  • 107
  • I was of the understanding that Internal classes or members are accessible only within files in the same assembly – neildt Dec 06 '13 at 18:05

1 Answers1

2

Serializing internal types using XmlSerializer

Solution here: https://web.archive.org/web/20160108180230/http://blogs.msdn.com/b/sowmy/archive/2008/10/04/serializing-internal-types-using-xmlserializer.aspx

Being able to serialize internal types is one of the common requests seen by the XmlSerializer team. It is a reasonable request from people shipping libraries. They do not want to make the XmlSerializer types public just for the sake of the serializer.

josliber
  • 43,891
  • 12
  • 98
  • 133
Shiva
  • 20,575
  • 14
  • 82
  • 112