Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#1,226 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

@commonsensesoftware ci sta già lavorando.

Dal 19/9/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

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

Lingua principale
C#
Stelle
3.2k
Fork
721
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di dotnet/aspnet-api-versioning

Tutte le issue di dotnet/aspnet-api-versioning

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.