-
Notifications
You must be signed in to change notification settings - Fork 10.3k
The JSON returned by SignalR does not contain the $type field #52342
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
Comments
I did a little investigate and I think these line is causing this issue.
The serializer is using the instance type (which is the derived type) to serialize and I assume it has no information of the base class. Perhaps a fix is to add the argument type along side the argument list. |
If other people hit this problem, here is an indirect workaround: dotnet/runtime#77532 (comment) Using such a custom resolver can force the type discriminator, It's not a pretty solution but it's better than the alternatives (pre-serializing, which means every parameter becomes a string; using a custom JSON converter on every implementation; passing an array of the base type; etc.) |
Is there an existing issue for this?
Describe the bug
When serializing descendant types, for methods that take a single (not a collection) parameter of the base type as an argument, the discriminator field is not added to JSON.
JSON for collection argument:
JSON for single argument:
This is similar to the problem described previously in #44852
Expected Behavior
I expect SignalR JSON to contain a $type field similar to responses from HTTP endpoints:
Steps To Reproduce
Repository with code showing the problem.
I used the following classes to show the problem:
Exceptions (if any)
No response
.NET Version
8.0.100
Anything else?
No response
The text was updated successfully, but these errors were encountered: