Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

.NET 11 RC - AOT Mode - System.NotSupportedException: ElementType is not initialized when `Microsoft.AspNetCore.Mvc.ApiExplorer.IsEnhancedModelMetadataSupported` is false.

Open
#1,226 1 comment 0 reactions 1 assignee View on GitHub

@commonsensesoftware is already working on this.

Since Sep 19, 2026.

Assessment

This issue has not been assessed yet.

Description

bug triage
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.

Image

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.cs and 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/aspnet-api-versioning

All issues in dotnet/aspnet-api-versioning

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.