Newtonsoft.Json icon indicating copy to clipboard operation
Newtonsoft.Json copied to clipboard

[Enhancement] when serializing/deserializing a netstandard lib used in .net framework/ net core

Open mike7ang1rdz opened this issue 8 months ago • 0 comments

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

mike7ang1rdz avatar Jun 27 '24 04:06 mike7ang1rdz