-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
net7: ValidationProblemDetails cannot be handled by JsonSerializerContext #83815
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsDescriptionWhen attempting to add the new Json serializer context source generators to my NET 7 MVC project, and following the apparently breaking changes in #77115, my Web Api attempted to return a
So, I added
Reproduction Steps
This will introduce the runtime error. Follow the instructions from the runtime, and you will receive the previously mentioned compile-time error as the source generator cannot generate boilerplate for VPD. Expected behavior
Actual behavior
Regression?A likely regression implied via #77115 but I cannot test here. Known WorkaroundsNo idea. Configurationdotnet sdk 7.0.4 Other informationNo response
|
Additionally, I'd love to know if there's a way to reserve the Json source generators for specific types and to just let the older runtime behaviour manage non-critical types (such as ValidationProblem) -- I find the documentation and subsequent changes between net6 and net7 and associated bugs around it too confusing. |
cc @eerhardt. The ASP.NET team is working to provide a solution specifically for that use case in .NET 8. As a temporary workaround, you could try using configuring your JsonSerializerOptions to use reflection-based fallback: options.TypeInfoResolver = JsonTypeInfoResolver.Combine(MySerializationContext.Default, new DefaultJsonTypeInfoResolver()); |
Addressed in dotnet/aspnetcore#43236. Should be fixed in .NET 8 Preview-2 |
A minor correction to your workaround (for anyone else who finds this thread): options.**JsonSerializerOptions**.TypeInfoResolver = JsonTypeInfoResolver.Combine( ... |
Description
When attempting to add the new Json serializer context source generators to my NET 7 MVC project, and following the apparently breaking changes in #77115, my Web Api attempted to return a
ValidationProblemDetails
and I received a runtime error of:So, I added
[JsonSerializable(typeof(Microsoft.AspNetCore.Mvc.ValidationProblemDetails))]
to theJsonSerializerContext
and now I get the following at compile time:Reproduction Steps
This will introduce the runtime error. Follow the instructions from the runtime, and you will receive the previously mentioned compile-time error as the source generator cannot generate boilerplate for VPD.
Expected behavior
[JsonSerializable(typeof(Microsoft.AspNetCore.Mvc.ValidationProblemDetails))]
should work on the custom context.Actual behavior
[JsonSerializable(typeof(Microsoft.AspNetCore.Mvc.ValidationProblemDetails))]
fails.Regression?
A likely regression implied via #77115 but I cannot test here.
Known Workarounds
No idea.
:(
Configuration
dotnet sdk 7.0.4
Other information
No response
The text was updated successfully, but these errors were encountered: