Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I am trying to integrate OpenAPI into an existing Blazor project which was recently upgraded to .NET 9.
I added the following project reference to the Server project:
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0-rc.2.24474.3" />
I modified the Startup.cs (yes this project has never migrated to the "new" Program.cs approach - but that should not affect the result):
public void ConfigureServices(IServiceCollection services)
{
...
services.AddMvc();
services.AddRazorPages();
services.AddOpenApi();
...
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<Startup> logger)
{
...
app.UseEndpoints(endpoints =>
{
endpoints.MapOpenApi();
});
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapRazorPages();
});
...
}
Note that this application is using traditional Controllers and Razor Pages - not minimal APIs.
When I run the application and browse to /openapi/v1.json I get a blank screen with no output:
The Visual Studio console contains the following information:
Microsoft.AspNetCore.Routing.EndpointMiddleware: Information: Executing endpoint 'HTTP: GET /openapi/{documentName}.json'
Microsoft.AspNetCore.Routing.EndpointMiddleware: Information: Executed endpoint 'HTTP: GET /openapi/{documentName}.json'
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished HTTP/1.1 GET http://localhost:44357/openapi/v1.json - 200 - - 981.2280ms
Expected Behavior
Browsing to /openapi/v1.json should display the Open API document
Steps To Reproduce
No response
Exceptions (if any)
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
.NET Version
9.0.0-rc.2.24473.5
Anything else?
Note that this application already had Swagger integrated previously:
services.AddSwaggerGen(options =>
{
options.CustomSchemaIds(type => type.ToString()); // Handle SchemaId already used for different type
});
services.TryAddSwagger(_useSwagger);
...
if (_useSwagger)
{
app.UseSwagger();
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/" + Constants.Version + "/swagger.json", Constants.PackageId + " " + Constants.Version); });
}
and the Swagger UI still works fine: