-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
Swagger (Get Index.html) fails when reflection-based serialization has been disabled. #54377
Comments
@emiliovmq I believe the issue here is the |
@captainsafia, thanks for your reply. Sorry if I don't fully understand your answer, but I have to say that I created the API as a "non webapiaot", in other words, I don't have the I think this is more a problem related to the fact that as of NET 8.0, the reflection-based serialization has been disabled for System.Text.Json (STJ), that is, all the de/serialization process occurs in the code generated by the I am asking for a solution where I can enable reflection-based serialization for those models/classes without needing to make a change request to the Swashbuckle project, and of course, keep using the generated source code for my models/classes. |
You should be able to achieve that already using the - options.JsonSerializerOptions.TypeInfoResolver = SerializationContext.Default;
+ options.JsonSerializerOptions.TypeInfoResolverChain.Add(SerializationContext.Default); |
@martincostello thanks for your comment...unfortunately the change doesn't work. However, if I enable the reflection-based serialization for STJ ( Now the question is...are my classes registered with the |
Hi, anything on this...any suggestion??? |
Closing as this is external and tracked in the Swashbuckle repo via domaindrivendev/Swashbuckle.AspNetCore#2550. |
Is there an existing issue for this?
Describe the bug
I'm using .NET 8.0 (8.0.2) and have set up a new simple API (the todo items API). By default, in .NET 8.0, the reflection-based serialization has been disabled for System.Text.Json. Whenever I try to get "swagger/index.html" file from my browser, an exception is thrown.
Expected Behavior
The "swagger/index.html" file is shown as expected.
Steps To Reproduce
This is the definition of the SerializationContext for STJ.
Exceptions (if any)
An unhandled exception has occurred while executing the request.
System.InvalidOperationException: Reflection-based serialization has been disabled for this application. Either use the source generator APIs or explicitly configure the 'JsonSerializerOptions.TypeInfoResolver' property.
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_JsonSerializerIsReflectionDisabled()
at System.Text.Json.JsonSerializerOptions.ConfigureForJsonSerializer()
at System.Text.Json.JsonSerializer.GetTypeInfo(JsonSerializerOptions options, Type inputType)
at System.Text.Json.JsonSerializer.GetTypeInfo[T](JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.GetIndexArguments()
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.RespondWithIndexHtml(HttpResponse response)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
12:18:53:684 [Error] Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware [19]: An unhandled exception has occurred while executing the request.
.NET Version
8.0.200
Anything else?
This is the class where the exception is thrown. Please, notice, this class is serializing the classes "ConfigObject", "OAuthConfigObject", and "Interceptors" using the serialization options built in the constructor.
The text was updated successfully, but these errors were encountered: