Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

OpenApiOperation copy constructor throws NullReferenceException #965

Copy link
Copy link
@DamianEdwards

Description

@DamianEdwards
Issue body actions

Attempting to use the new copy constructors in the 1.4.0-preview1 release in an ASP.NET Core minimal APIs app and getting a NullReferenceException from the OpenApiExternalDocs constructor.

Stack trace:

System.NullReferenceException: Object reference not set to an instance of an object.
         at Microsoft.OpenApi.Models.OpenApiExternalDocs..ctor(OpenApiExternalDocs externalDocs)
         at Microsoft.OpenApi.Models.OpenApiOperation..ctor(OpenApiOperation operation)
         at Program.<>c.<<Main>$>b__0_4(OpenApiOperation o) in C:\src\local\7.0.0-rc.1\WebApplication6\WebApplication6\Program.cs:line 63
         at Microsoft.AspNetCore.Builder.OpenApiEndpointConventionBuilderExtensions.AddAndConfigureOperationForEndpoint(EndpointBuilder endpointBuilder, Func`2 configure)
         at Microsoft.AspNetCore.Builder.OpenApiEndpointConventionBuilderExtensions.<>c__DisplayClass1_0`1.<WithOpenApi>b__0(EndpointBuilder endpointBuilder)
         at Microsoft.AspNetCore.Routing.RouteEndpointDataSource.CreateRouteEndpointBuilder(RouteEntry entry, RoutePattern groupPrefix, IReadOnlyList`1 groupConventions)
         at Microsoft.AspNetCore.Routing.RouteEndpointDataSource.get_Endpoints()
         at Microsoft.AspNetCore.Routing.CompositeEndpointDataSource.CreateEndpointsUnsynchronized()
         at Microsoft.AspNetCore.Routing.CompositeEndpointDataSource.EnsureEndpointsInitialized()
         at Microsoft.AspNetCore.Routing.DataSourceDependentCache`1.Initialize()
         at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory)
         at Microsoft.AspNetCore.Routing.Matching.DataSourceDependentMatcher..ctor(EndpointDataSource dataSource, Lifetime lifetime, Func`1 matcherBuilderFactory)
         at Microsoft.AspNetCore.Routing.Matching.DfaMatcherFactory.CreateMatcher(EndpointDataSource dataSource)
         at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.InitializeCoreAsync()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<Invoke>g__AwaitMatcher|8_0(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task`1 matcherTask)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Repro code, using a nightly build of .NET 7 rc.1 SDK, new project created via dotnet new webapi -minimal:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

app.UseSwagger();
app.UseSwaggerUI();

app.MapGet("/testopenapi", () => "Open API")
    .WithOpenApi(o => new(o));

app.Run();
Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

type:bugA broken experienceA broken experience

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.