'Disabling ProxyCreationEnabled breaks JsonConvert.SerializeObject and quits VS debugging
I'm trying to serialize to json some data from EF6 DB first entities.
The first problem was that I was doing lazy loading, and closed the data context, then I got Context Disposed error when doing JsonConvert.SerializeObject(dataFromEntities).
So I set context.Configuraton.ProxyCreationEnabled = false; so all propreties that are not included are null by default. The problem now is that when i try to serialize, Visual Studio 2019 just quit debuggin and don't give any exception message. I have my code in a try-catch but it don't catch anything.
What I'm doing wrong?
I also tried to disable lazy loading but the result is the same. Here is the code:
using (var oContext = new DBContext.UDCSDesign())
{
oContext.Configuration.ProxyCreationEnabled = false; //If i remove this line I get Object Disposed error on serialization
var oFieldDictionaryList = oContext.FieldDictionary
.Include(oField => oField.DropdownItem)
.ToList();
}
And then:
try{
string sDocJsonData = JsonConvert.SerializeObject(oFieldDictionaryList, Formatting.None,
new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Serialize
});
}
catch (Exception ex){
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
