When you upgrade Swashbuckle.AspNetCore and Swashbuckle.AspNetCore.Swagger packages to version 10.0.1, you may encounter the following error:
The type or namespace name 'OpenApiReference' could not be found
What's the Problem?
In Swashbuckle 10.0+, the OpenApiReference class has been completely removed. This breaking change prevents older code from compiling.
If you're using a structure like this for security scheme definitions, it will no longer work:
// ❌ This code does NOT work with Swashbuckle 10.0+
c.AddSecurityRequirement(
new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference // <- This class was removed!
{
Type = ReferenceType.SecurityScheme,
Id = "Bearer"
}
},
new string[] { }
}
});Solution
Swashbuckle 10.0+ introduces a new constructor-based approach called OpenApiSecuritySchemeReference. You need to update your code as follows:
// ✅ Correct usage for Swashbuckle 10.0+
c.AddSecurityRequirement(
new OpenApiSecurityRequirement
{
{
new OpenApiSecuritySchemeReference("Bearer"),
new string[] { }
}
});Migration Steps
Step 1: Find Your Existing Code
Search for OpenApiReference usage in your Program.cs or Swagger extension files.
Step 2: Switch to New Structure
Replace all security scheme definitions using OpenApiReference with the OpenApiSecuritySchemeReference constructor.
Step 3: Test
Run your application and ensure Swagger UI loads correctly and the authorization lock icon appears.
Conclusion
This change was made to make Swashbuckle more compliant with OpenAPI 3.1 standards. The new approach provides a cleaner and more understandable API.