You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A union that System.Text.Json cannot classify makes every Minimal API route return 500 (and fails startup with MVC) #69826
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcbugThis issue describes a behavior which is not expected - a bug.
Part of #64599. 11.0.100-rc.2.26504.105; the same behaviour on RC 1.
One Minimal API endpoint taking a union that the structural classifier refuses (JsonUnionTypeStructuralClassifier, #129805) makes endpoint building throw. The request then returns 500 for every route in the app, including routes that don't use the union:
publicrecordNotRequired;publicrecordPendingApproval;publicrecordPartlyApproved(GuidApprover);[JsonUnion(TypeClassifier=typeof(JsonUnionTypeStructuralClassifier))]publicunionApproval(NotRequired,PendingApproval,PartlyApproved);app.MapGet("/ok",()=>"ok");app.MapPost("/x",(Approvala)=>a);// GET /ok => 500 NotSupportedException: The JsonUnionTypeStructuralClassifier cannot classify// union type 'Approval' because the case type 'NotRequired' can never be selected uniquely...
The throw comes from RouteEndpointDataSource.CreateRouteEndpointBuilder / get_Endpoints().
Setup
Result
Minimal API only
startup succeeds; every route 500 on the first request
AddControllers() plus the bad Minimal API endpoint
StartAsync throws NotSupportedException
AddAuthorization()
startup throws
The bad union only on an MVC action
only that action fails (500); /ok and other MVC routes return 200
A union ambiguous only at read time (no classifier)
only that endpoint fails (400)
The structural classifier rejecting indistinguishable cases is by design (#129805). The question is the scope of the failure. Is it intended that one such endpoint takes the whole endpoint table down on Minimal APIs, or should the exception be scoped to that endpoint, as MVC already does?
This isn't specific to unions. For example, an unregistered service parameter on a MapGet can be inferred as a body parameter and fail endpoint construction. That can prevent unrelated routes from working too. We deliberately reject inferred GET bodies (#35405); explicit [FromBody] is supported.
I don't think we should change the product behavior this late in .NET 11. Isolating these failures would need a broader look at endpoint-construction errors, not just a special case for unions. Unconditionally evaluating endpoints at startup would also change when user-defined code runs, and it would not cover endpoints added after startup.
I'd be open to revisiting this after .NET 11. Better diagnostics and opt-in early validation seem like good starting points. Per-endpoint isolation is worth considering for failures that are genuinely local to an endpoint, but not every routing error can be isolated that way.
Thanks. Agreed on both points: it isn't union-specific (an ordinary GET where a record parameter is inferred as a body exhibits the same behavior in the probes), and it makes sense to avoid a change this late in the .NET 11 cycle.
One data point for the post-.NET 11 discussion: endpoints are already built at startup in most apps, albeit incidentally. AddAuthorization() (which AddControllers() registers) makes the authorization policy cache enumerate the endpoints inside StartAsync.
Because of this, the same bad endpoint today either fails at startup or turns every request into a 500. Which one happens depends entirely on whether an unrelated service is registered (as seen in rows 2 and 3 of the table in the issue description). An opt-in early validation would make this incidental behavior deliberate and available without authorization.
Could this get a milestone (Backlog or .NET 12) so it gets picked up in the next cycle?
Re-ran on GA (SDK 11.0.100, ASP.NET Core 11.0.0). Both failures reproduce unchanged:
Without authorization: one Minimal API endpoint taking the unclassifiable union (TwoEmpty) makes GET /ok return 500 with the classifier's NotSupportedException, even as the first request the host sees, inside a MapGroup, and for MVC routes (GET /mvc/ok) beside it.
With AddAuthorization() or AddControllers(): startup throws from AuthorizationPolicyCache..ctor. AddOpenApi() alone starts, then every request is 500.
The same union on an MVC action still fails only that action.
One detail on the "not union-specific" point. The non-union control (a GET whose record parameter is inferred as a body) behaves like the union only on the reflection path:
reflection
RDG
non-union inferred GET body, GET /ok
500
200
unclassifiable union endpoint, GET /ok
500
500
So with the Request Delegate Generator the non-union endpoint failure is contained to its own endpoint, and the union one still takes the route table down. That may matter when the diagnostics and per-endpoint isolation work is scoped for .NET 12.
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcbugThis issue describes a behavior which is not expected - a bug.
Activity
github-actions commentedon Oct 14, 2026
Triage Summary
Area:
area-minimal(exception thrown fromRouteEndpointDataSourceendpoint building)Type:
Bug(one endpoint's build failure affects all routes, unlike MVC)Potential Duplicates
Notes
RouteEndpointDataSource.CreateRouteEndpointBuilder/Endpointsinsrc/Http/Routing/src/Builder/RouteEndpointDataSource.cs.Youssef1313 commentedon Oct 14, 2026
@DeagleGross
halter73 commentedon Oct 15, 2026
This isn't specific to unions. For example, an unregistered service parameter on a
MapGetcan be inferred as a body parameter and fail endpoint construction. That can prevent unrelated routes from working too. We deliberately reject inferred GET bodies (#35405); explicit[FromBody]is supported.I don't think we should change the product behavior this late in .NET 11. Isolating these failures would need a broader look at endpoint-construction errors, not just a special case for unions. Unconditionally evaluating endpoints at startup would also change when user-defined code runs, and it would not cover endpoints added after startup.
I'd be open to revisiting this after .NET 11. Better diagnostics and opt-in early validation seem like good starting points. Per-endpoint isolation is worth considering for failures that are genuinely local to an endpoint, but not every routing error can be isolated that way.
robertodalmonte commentedon Oct 16, 2026
Thanks. Agreed on both points: it isn't union-specific (an ordinary GET where a record parameter is inferred as a body exhibits the same behavior in the probes), and it makes sense to avoid a change this late in the .NET 11 cycle.
One data point for the post-.NET 11 discussion: endpoints are already built at startup in most apps, albeit incidentally.
AddAuthorization()(whichAddControllers()registers) makes the authorization policy cache enumerate the endpoints insideStartAsync.Because of this, the same bad endpoint today either fails at startup or turns every request into a 500. Which one happens depends entirely on whether an unrelated service is registered (as seen in rows 2 and 3 of the table in the issue description). An opt-in early validation would make this incidental behavior deliberate and available without authorization.
Could this get a milestone (Backlog or .NET 12) so it gets picked up in the next cycle?
robertodalmonte commentedon Nov 11, 2026
Re-ran on GA (SDK
11.0.100, ASP.NET Core11.0.0). Both failures reproduce unchanged:TwoEmpty) makesGET /okreturn 500 with the classifier'sNotSupportedException, even as the first request the host sees, inside aMapGroup, and for MVC routes (GET /mvc/ok) beside it.AddAuthorization()orAddControllers(): startup throws fromAuthorizationPolicyCache..ctor.AddOpenApi()alone starts, then every request is 500.Captures:
QOareflection,QOaRDG,Probe2section G (RDG).One detail on the "not union-specific" point. The non-union control (a GET whose record parameter is inferred as a body) behaves like the union only on the reflection path:
GET /okGET /okSo with the Request Delegate Generator the non-union endpoint failure is contained to its own endpoint, and the union one still takes the route table down. That may matter when the diagnostics and per-endpoint isolation work is scoped for .NET 12.
DeagleGross commentedon Nov 11, 2026
Thanks for providing more info; we put the item in .NET 12 Planning - hopefully we will work on this an include in the next .NET release