title: How to resolve System.RuntimeType is inaccessible due to its protection level. Only public types can be processed.?
body: <p>I am trying to serialize my class. But i got the following exception,</p>
  
  <pre><code>  System.InvalidOperationException was unhandled
    HResult=-2146233079
    Message=There was an error generating the XML document.
    Source=System.Xml
    StackTrace:
         at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
         at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o)
         at FormDemo.Form1.PivotGridSettings() in D:\Feature\XML Serialization\CS\Form1.cs:line 75
         at FormDemo.Form1..ctor() in D:\Feature\XML Serialization\CS\Form1.cs:line 32
         at FormDemo.Program.Main() in D:\Feature\XML Serialization\CS\Program.cs:line 25
         at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
         at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
         at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
         at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
         at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
         at System.Threading.ThreadHelper.ThreadStart()
    InnerException: System.InvalidOperationException
         HResult=-2146233079
         Message=System.RuntimeType is inaccessible due to its protection level. Only public types can be processed.
         Source=System.Xml
         StackTrace:
              at System.Xml.Serialization.TypeDesc.CheckSupported()
              at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)
              at System.Xml.Serialization.XmlSerializationWriter.CreateUnknownTypeException(Type type)
              at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterCustomSerializer.Write20_Type(String n, String ns, Type o, Boolean isNullable, Boolean needType)
              at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterCustomSerializer.Write24_CustomClass(String n, String ns, CustomEngine o, Boolean isNullable, Boolean needType)
              at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterCustomSerializer.Write25_CustomClass(String n, String ns, CustomSeriaizer o, Boolean isNullable, Boolean needType)
              at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterCustomSerializer.Write26_CustomSerializer(Object o)
         InnerException: 
  </code></pre>
  
  <p>My Serialization code is</p>
  
  <pre><code>XmlTextWriter xw = new XmlTextWriter("CustomClassSchema.xml", System.Text.Encoding.UTF8);
  xw.Formatting = Formatting.Indented;
  XmlSerializer serializer = new XmlSerializer(typeof(CustomSerializer));
  CustomSerializer customSerializer = new CustomSerializer()
  serializer.Serialize(xw, customSerializer);
  </code></pre>
  
  <p>Please help me to resolve this issue. Is there any customization that i need to do with my custom class or any?</p>