I've a concrete class below which inherits from abstract class:
[Serializable]
public class MyConcreteClass : MyAbstractClass
{
public string MyProperty { get; set; }
}
[Serializable]
public abstract class MyAbstractClass { }
NewtonSoft JSON Serializer throws exception below when trying to de/serialize MyconcreteClass class:
Newtonsoft.Json.JsonSerializationException: Could not create an instance of type MyAbstractClass. Type is an interface or abstract class and cannot be instantiated. Path ....
Did a bit of googling and found this setting below:
var settings = new JsonSerializerSettings()
{
TypeNameHandling = TypeNameHandling.All
};
If I use above setting i.e. TypeNameHandling.All, the error goes away.
Questions in my mind:
Is this is the correct approach to fix this issue (And not sure what this option is not out of box)
Any performance or negative impacts that I should be aware of with this setting.
Thanks.