Newtonsoft.Json
Newtonsoft.Json copied to clipboard
[Enhancement] when serializing/deserializing a netstandard lib used in .net framework/ net core
When serializing objects in .NET Framework using Newtonsoft JSON, the serializer includes the assembly name in the type name, which is mscorlib for .NET Framework. However, when deserializing in .NET Core, the expected assembly name is System.Private.CoreLib, not mscorlib. This discrepancy causes a TypeNameHandling bug where the deserializer cannot find the type because it’s looking in the wrong assembly. This issue arises because .NET Core and .NET Framework have different core libraries, leading to different type names.
Source/destination types
// Put the types you are serializing or deserializing here
Source/destination JSON
{ "$type": "System.Object, mscorlib", "Property1": "Value1", "Property2": 123 }
Expected behavior
it should use TypeForwardedFrom attribute to handle this problem automatically without having to use jsonserializesettings
Actual behavior
throws exception because the assembly wasn't found.
Steps to reproduce
Deserialize the json in net.core