JamesNK/Newtonsoft.Json

Deserializing object of missing class as it's Base class (C#)

GuyDayannn opened this issue · 1 comments

Hi,
I wanted to ask if the follow scenario possible.
I'm developing an app that uses a plugin so it loads derived class of a base class from a dll.

For example, I my code base has a base class:

public class BaseClass
{
  // some properties
}

and the derived class comes from a dll that loads at runtime:

public class DerivedClass : BaseClass
{
  // some properties
}

I'm using TypeNameHandling = TypeNameHandling.All for serializing and deserializing
When I serialize and deserialize objects using the DLL, everything works fine.
However, when I remove the DLL and attempt to deserialize a file containing derived class objects, deserialization fails.
Is there an option to ensure that deserialization does not fail, but instead treats the derived class as the base class?

Thanks for the help,
Guy.

We used JsonSerializerSettings Error = HandleDeserializationError property