Skip to content
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

BUG TypeName provided by SerializationBinder gets manipulated afterwards #2439

Closed
omghb opened this issue Dec 17, 2020 · 2 comments
Closed

Comments

@omghb
Copy link

omghb commented Dec 17, 2020

Source/destination types

https://github.com/omghb/JsonSerializationBinderBug/blob/main/JsonSerializationBinderBug/SerializationBinderBugDemo.cs

Source/destination JSON

{"$id":"1","Data":{"$id":"2","$type":"TestClass`3[Int32,Double]","Item1":42,"Item2":3.1415,"Item3":"Luke"}}

Expected behavior

{"$id":"1","Data":{"$id":"2","$type":"TestClass`3[Int32,Double,String]","Item1":42,"Item2":3.1415,"Item3":"Luke"}}

Actual behavior

Assert.Equal() Failure
                                  ↓ (pos 24)
Expected: ···Class`3[Int32, Double, String]
Actual:   ···Class`3[Int32, Double]
                                  ↑ (pos 24)

Steps to reproduce

I have published a sample xUnit test to reproduce this issue here:
https://github.com/omghb/JsonSerializationBinderBug

Workaround

When the KnownTypesBinder uses other char than "[", "]" and "," then this works correct. It seems that Newtonsoft.Json does some post-processing with the typeName provided by the SerializationBinding and interprets the chars "," and "[", "]" in some way.

@TylerBrinkley
Copy link
Contributor

TylerBrinkley commented Dec 17, 2020

You need to specify TypeNameAssemblyFormatHandling.Full so that the serializer doesn't try to strip out the full assembly name which is what it's trying to do here.

@omghb
Copy link
Author

omghb commented Dec 17, 2020

Thanks for providing the correct setting. This fixed my issue.

This might even gain a little bit performance because RemoveAssemblyDetails will not be called - as it should not when a custom SerializationBinder takes over.

return RemoveAssemblyDetails(fullyQualifiedTypeName);

@omghb omghb closed this as completed Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants