I'm getting following error in deserializing a json object : (Using JSON.NET)
Cannot create an abstract class.
at System.Runtime.Serialization.FormatterServices.nativeGetUninitializedObject(RuntimeType type)
at ReadDataSourceBaseFromJson(XmlReaderDelegator , XmlObjectSerializerReadContextComplexJson , XmlDictionaryString , XmlDictionaryString[] )
And exact line giving the error is:
return _serializer.ReadObject(stream); // _serializer is DataContractJsonSerializer
I can not reproduce this issue in my local machine, or in the stage machine in hosted environment. JSON is deserialized perfectly
However the issue is reproducible consistently in the QA and production environment. I've tried with
- QA database
- QA code in release mode, including all DLLs
- QA web configs
But still can't produce. JSON object is stored in database and I'm trying to serialize it into classes.
What else I can do to reproduce the issue?
EDIT
Code leading up to the error line is:
var json = JObject.Parse(definition);
var foo = json.GetValue("outerRoot").ToString();
var dataDefinition = _serializer.Deserialize(foo);
And Deserialize function is
public returnType Deserialize(string serializedData)
{
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(serializedData)))
{
return (returnType)_serializer.ReadObject(stream);
}
}
So I am using JSON.Net to strip out the outer most node and deserializing what's inside.