Click here to Skip to main content
15,887,416 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I have a class as follows

C#
[Serializable]
public class test
{
    public string Name { get; set; }
    public Type LocalType { get; set; }
}


When I try to serialize this class it gives the exception

"System.RuntimeType is inaccessible due to its protection level. Only public types can be processed." Is there anything i'm missing or is it just that Type property cannot be serialized?

Thanks in advance.
Posted
Updated 22-Feb-17 16:07pm
v2

 
Share this answer
 
Your "LocalType" member is returning a System.Type. That type, System.Type, is implemented, in part, with System.RuntimeType. Which in turn is not public. Therefore, the "LocalType" property cannot be serialized.

Either mark "LocalType" as [XmlIgnore] or change it to something that can be serialized.
 
Share this answer
 
Comments
Dave Kreskowiak 22-Feb-17 22:19pm    
Gotta check the dates on posts. This one is 4 years old.
TheGreatAndPowerfulOz 23-Feb-17 9:48am    
LOL. I looked for the date in the view that I had. Which was the result of a google search for something else. The date was not displayed until after I answered the question. Ahh, well, at least maybe this may help some other poor fool.
Richard Deeming 23-Feb-17 16:44pm    
You might want to report that over in Bugs and Suggs[^]. It might explain why we get so many new answers posted on ancient questions. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900