I'd like to serialize my linq object to json. The linq object is disconnected, meaning the datacontext was disposed long time ago. There are "related" objects which were not loaded during the object load process which can't be accessed (When accessed, runtime error return "Cannot access a disposed object." because the datacontext is gone)
Is there any json/xml converter with the ability to serialize this object? I don't want to chanage the dbml
Is there any serialization object with the ability to configure ignore exception properties or so?
To reproduce that issue, create this object:
public class HelpMeToSerialize
{
public string Name;
public int Age
{
get
{
throw new Exception("Can't access this on runtime");
}
set
{
}
}
}
And simply serialize it with this code or any other code you have:
HelpMeToSerialize obj = new HelpMeToSerialize();
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(obj.GetType());
x.Serialize(Console.Out, obj);