.NET 11 RC - AOT Mode - System.NotSupportedException: ElementType is not initialized when `Microsoft.AspNetCore.Mvc.ApiExplorer.IsEnhancedModelMetadataSupported` is false.
@commonsensesoftware is already working on this.
Since Sep 19, 2026.
Assessment
This issue has not been assessed yet.
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
With <PublishAot>true</PublishAot> in the project (even under dotnet run), requesting a versioned OpenAPI doc throws.
Commenting out PublishAot in *.csproj fixes it. Reproduces with both DateOnly-based and integer ApiVersions, so unrelated to versioning scheme.
Expected Behavior
Asp.Versioning.OpenApi 10.2.3 itself declares IsAotCompatible: True / IsTrimmable: True in its assembly metadata which means AOT mode is supported. The package should succeed in generating OpenAPI JSON document with .NET 11 SDK.
Steps To Reproduce
> dotnet --info # 11.0.100-rc.1
> dotnet new webapiaot -n api-explorer
> cd api-explorer
> dotnet add package Asp.Versioning.OpenApi # 10.2.3
> dotnet add package Scalar.AspNetCore
- Edit
Program.csand add code to version minimal API
...
builder.Services.AddApiVersioning(options =>
{
options.ApiVersionReader = new HeaderApiVersionReader("X-Product-Version");
options.ReportApiVersions = true;
})
.AddApiExplorer(options => {
options.GroupNameFormat = "'v'yyy-MM";
})
.AddOpenApi(options =>
{
options.Document.AddScalarTransformers();
});
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.MapOpenApi().WithDocumentPerVersion();
app.MapScalarApiReference(options =>
{
var descriptions = app.DescribeApiVersions();
for ( var i = 0; i < descriptions.Count; i++ )
{
var description = descriptions[i];
var isDefault = i == descriptions.Count - 1;
options.AddDocument( description.GroupName, description.GroupName, isDefault: isDefault );
}
});
}
Todo[] sampleTodos =
[
new(1, "Walk the dog"),
new(2, "Do the dishes", DateOnly.FromDateTime(DateTime.Now)),
new(3, "Do the laundry", DateOnly.FromDateTime(DateTime.Now.AddDays(1))),
new(4, "Clean the bathroom"),
new(5, "Clean the car", DateOnly.FromDateTime(DateTime.Now.AddDays(2)))
];
var versionSet = app.NewApiVersionSet("Product")
.HasDeprecatedApiVersion(new ApiVersion(new DateOnly(2026,8,1)))
.HasApiVersion(new ApiVersion(new DateOnly(2026,9,1)))
.ReportApiVersions()
.Build();
var todosApi = app.MapGroup("/todos").WithApiVersionSet(versionSet);
todosApi.MapGet("/", () => sampleTodos)
.WithName("GetTodos");
todosApi.MapGet("/{id}", Results<Ok<Todo>, NotFound> (int id) =>
sampleTodos.FirstOrDefault(a => a.Id == id) is { } todo
? TypedResults.Ok(todo)
: TypedResults.NotFound())
.WithName("GetTodoById").MapToApiVersion(new ApiVersion(new DateOnly(2026,8,1)));
app.Run();
Exceptions (if any)
System.NotSupportedException: ElementType is not initialized when `Microsoft.AspNetCore.Mvc.ApiExplorer.IsEnhancedModelMetadataSupported` is false.
at Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.get_ElementType()
at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.get_ElementMetadata()
at Asp.Versioning.ApiExplorer.VersionedModelMetadataProvider.Describe(ModelMetadata metadata, Type type, ApiVersion apiVersion, Boolean minimalApi)
at Asp.Versioning.ApiExplorer.VersionedModelMetadataProvider.OnProvidersExecuted(ApiDescriptionProviderContext context)
at Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollectionProvider.GetCollection(ActionDescriptorCollection actionDescriptors)
at Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollectionProvider.get_ApiDescriptionGroups()
at Microsoft.AspNetCore.OpenApi.OpenApiDocumentService.GetOpenApiPathsAsync(OpenApiDocument document, IServiceProvider scopedServiceProvider, IOpenApiOperationTransformer[] operationTransformers, IOpenApiSchemaTransformer[] schemaTransformers, CancellationToken cancellationToken)
at Microsoft.AspNetCore.OpenApi.OpenApiDocumentService.GetOpenApiDocumentAsync(IServiceProvider scopedServiceProvider, HttpRequest httpRequest, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Builder.OpenApiEndpointRouteBuilderExtensions.<>c__DisplayClass0_0.<<MapOpenApi>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Http.Generated.<GeneratedRouteBuilderExtensions_g>F2F695FFF0C57E2AC66C44A89193E354033830917758BE7A77025BFF91AF84311__GeneratedRouteBuilderExtensionsCore.<>c__DisplayClass2_0.<<MapGet0>g__RequestHandler|5>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
.NET Version
11.0.100-rc.1
Anything else?
No response
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 721
- PR merge metrics
- No merged PRs in 30d
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/aspnet-api-versioning
-
VersionedOpenApiOptionsFactory race: concurrent document requests cause NullReferenceException or unconfigured documentPossibly taken @commonsensesoftware claimed this 8 days ago. Openbug triage
dotnet/aspnet-api-versioning#1228 · 1 assignee ·
-
InvalidOperationException when create schema on transformerPossibly taken @commonsensesoftware claimed this 8 days ago. Openasp.net core triage
dotnet/aspnet-api-versioning#1227 · 1 assignee ·
-
xmldoc file detection by assembly from a referenced projectPossibly taken @commonsensesoftware claimed this 23 days ago. Openasp.net core enhancement
dotnet/aspnet-api-versioning#1224 · 3 comments · 1 assignee ·
-
Feature request: declarative attribute for endpoints introduced in a specific API versionMay be free again @commonsensesoftware claimed this 52 days ago, and no pull request is open. Openasp.net core enhancement
dotnet/aspnet-api-versioning#1183 · 7 comments · 1 assignee ·
-
Using versioning in conjunction with yarp reverse proxyMay be free again @commonsensesoftware claimed this 1397 days ago, and no pull request is open. Openasp.net core enhancement question
dotnet/aspnet-api-versioning#930 · 7 comments · 1 assignee ·
All issues in dotnet/aspnet-api-versioning
Similar issues
-
area-ai untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
dotnet/extensions#7790 ·
Maintainers usually reply within 1 day
-
P2 testing
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
area-Infrastructure-coreclr os-ios os-maccatalyst os-tvos untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
dotnet/runtime#134766 · 3 comments ·
Maintainers usually reply within 1 day
-
0 - Backlog Bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
BrighterCommand/Brighter#4444 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day