-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cross Platform Primitive Types with Generics #1972
Comments
Similar issue: #1378 However, it would be nice if at least the primitive types are supported by default. ( |
Stumbling on this issue porting my projects from NetFramework to Net5. I'm surprised this is not a more high profile issue since this is probably happening to many people since the existence of NetCore. Any project using json serialization for messages between micro-services using different framework will encounter this on basic primitive types. #1378 offers a workaround, but it's not perfect, and also requires old NetFramework services to be updated to support the inverse (netcore to netframework). Since the issue haven't moved since 2019, should I assume it's not in the plan to offer a transparent fix officially? |
This repo is (almost) dead. Use |
As much as |
Yes, there is no parity in features yet. But at least with the appearance of net5 there are more green checkmarks in the second column - https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-migrate-from-newtonsoft-how-to?pivots=dotnet-5-0#table-of-differences-between-newtonsoftjson-and-systemtextjson See also dotnet/runtime#41313 |
Yeah this issue is definitely going to be seen more and more when porting apps to .NET 5. I'll share our temporary but not ideal solution was removing all instances of |
I don't know what the status of JSON.net is, but I'd imagine it stay around as |
@Dunge This issue occurred when serializing on .NET 5 and then deserializing on .NET Framework 4 right? Want to make sure this fully fixes the issue |
The value in $type is written and read by Alternatively you could wrap the default one (DefaultSerializationBinder) and do something hacky like a string replace on the type name. For example, replace |
potential workaround?
|
@danebou Yes. Somehow, .NET Framework4 serialized strings with mscorlib can deserialize without issue in a .NET5 project, but not the inverse. @SimonCropp This seems to be working for me. In any case, it's much simpler and cleaner than @arthurvaverko-kaltura workaround in #1378. In my situation, the |
@Dunge yeah we confirmed and rolled out the AssemblyResolve workaround |
That's a far better solution. I'll close out my PR. |
@danebou i didnt consider my suggestion a "fix", just a workaround. My preference would be that this scenario was supported OOTB |
Ah gotcha. Yeah, I'm in favor of OOTB too. It at least seems like a cleaner solution. However, it might bring unexpected behavior to the user, if say they relied on that assembly check to determine the platform (very bad implementation, but still). @JamesNK Regardless of the implementation, is this something you feel like should be handled with JSON.net, or left up to the user to apply a workaround? I think the decision on that would either close out this issue, or allow us to get a PR up. |
I'm not sure. I'm hesitant to hardcode behavior on assembly names. If it isn't automatically supported, at the very least the workaround should be added to the documentation. |
@JamesNK is previously worked ootb, should it instead be considered a bug in dotnet? |
An alternative solution is to leave the assembly name off when serializing primitives. I don't know which option that would fit into |
I'll close out this issue. The workaround SimonCropp suggested is great. |
Source/destination types
Source/destination JSON
With UWP/.NetCore:
With .NET Framework
Expected behavior
Successful deserialization. Or the suggested fix of serializing primitives without the assembly name:
Actual behavior
Runtime Exception:
Steps to reproduce
TypeNameHandling.Objects
)a. That is, .NETFramework if UWP/.NETCore, and vice versa.
The text was updated successfully, but these errors were encountered: