Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
ASPDEPR002:
The WithOpenApi extension methods are deprecated starting in .NET 10. Using these methods produces the ASPDEPR002 diagnostic at compile time. The functionality they provided is now available through the built-in OpenAPI document generation pipeline.
Workarounds
Remove .WithOpenApi() calls from your code.
If you used
Microsoft.AspNetCore.OpenApifor document generation, use theAddOpenApiOperationTransformerextension method instead.Before:
using Microsoft.AspNetCore.OpenApi; var builder = WebApplication.CreateBuilder(); var app = builder.Build(); app.MapGet("/weather", () => ...) .WithOpenApi(operation => { // Per-endpoint tweaks operation.Summary = "Gets the current weather report."; operation.Description = "Returns a short description and emoji."; return operation; }); app.Run();After:
using Microsoft.AspNetCore.OpenApi; var builder = WebApplication.CreateBuilder(); var app = builder.Build(); app.MapGet("/weather", () => ...) .AddOpenApiOperationTransformer((operation, context, ct) => { // Per-endpoint tweaks operation.Summary = "Gets the current weather report."; operation.Description = "Returns a short description and emoji."; return Task.CompletedTask; }); app.Run();If you used
Swashbucklefor document generation, use theIOperationFilterAPI.If you used
NSwagfor document generation, use theIOperationProcessorAPI.
Suppress a warning
If you must use the deprecated APIs, you can suppress the warning in code or in your project file.
To suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the warning.
// Disable the warning.
#pragma warning disable ASPDEPR002
// Code that uses deprecated API.
// ...
// Re-enable the warning.
#pragma warning restore ASPDEPR002
To suppress all the ASPDEPR002 warnings in your project, add a <NoWarn> property to your project file.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
...
<NoWarn>$(NoWarn);ASPDEPR002</NoWarn>
</PropertyGroup>
</Project>
See also
ASP.NET Core