Endpoint HTTP: GET /patients contains CORS metadata, but a middleware was not found that supports CORS. means an endpoint carries .RequireCors(...) but the pipeline has no app.UseCors(). Add app.UseCors(); before the endpoints are mapped and the 500 becomes a normal response with the CORS headers.

The app in this test called AddCors in the services and had no app.UseCors(). Adding that one line was the whole change, and the same request then answered with Access-Control-Allow-Origin.

The error

The request sent an Origin header, as a browser on another origin would. The response was the Development exception page as plain text, and the server console logged the same exception:

PS> curl.exe -s -i -H "Origin: http://localhost:5173" http://127.0.0.1:15630/patients
HTTP/1.1 500 Internal Server Error
Content-Type: text/plain; charset=utf-8
Date: Sat, 14 Nov 2026 01:16:05 GMT
Server: Kestrel
Transfer-Encoding: chunked

System.InvalidOperationException: Endpoint HTTP: GET /patients contains CORS metadata, but a middleware was not found that supports CORS.
Configure your application startup by adding app.UseCors() in the application startup code. If there are calls to app.UseRouting() and app.UseEndpoints(...), the call to app.UseCors() must go between them.
...

Why it happens

The code that produced it:

...
builder.Services.AddCors(options =>
{
    options.AddPolicy("Frontend", policy => policy.WithOrigins("http://localhost:5173"));
});

var app = builder.Build();

app.MapGet("/patients", () => new[] { "Maria Garcia", "David Chen" })
    .RequireCors("Frontend");

app.Run();

RequireCors("Frontend") attaches the policy name to the endpoint as metadata. When the request reached the endpoint, nothing in the pipeline had handled that metadata, and ASP.NET Core stopped with an exception rather than answering without CORS headers. The app built and started without a warning; the error came on the first request. The second sentence of the message gives the fix and the rule for apps that call UseRouting and UseEndpoints themselves.

The fix

...
var app = builder.Build();

app.UseCors();

app.MapGet("/patients", () => new[] { "Maria Garcia", "David Chen" })
    .RequireCors("Frontend");
...

UseCors() without a name was enough here, because the endpoint names its own policy. The call sits after builder.Build() and before MapGet. This minimal API calls neither UseRouting nor UseEndpoints, so the ordering rule in the second sentence of the message had nothing to apply to, and the single added line was the whole change. The same request now returned the data with the allowed origin:

PS> curl.exe -s -i -H "Origin: http://localhost:5173" http://127.0.0.1:15630/patients
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Date: Sat, 14 Nov 2026 01:16:07 GMT
Server: Kestrel
Access-Control-Allow-Origin: http://localhost:5173
Transfer-Encoding: chunked

["Maria Garcia","David Chen"]

How it was reproduced

A minimal API made with dotnet new web -f net10.0 on SDK 11.0.100, running on Microsoft.AspNetCore.App 10.0.15 in the Development environment, built and started by a small script, start.ps1, which runs dotnet build -nologo -v q in the project folder and then bin\Debug\net10.0\FixLab.exe --urls http://127.0.0.1:15630. One endpoint with RequireCors("Frontend"), no UseCors, and a single curl.exe request with an Origin header; the same request after adding app.UseCors() returned 200 with Access-Control-Allow-Origin.

Frequently asked

What does 'contains CORS metadata, but a middleware was not found that supports CORS' mean?
The endpoint has RequireCors, but app.UseCors() is missing from the pipeline. The request fails with a 500 instead of being answered.
Is AddCors enough to enable CORS in ASP.NET Core?
Not in the test. With AddCors and no app.UseCors() the endpoint failed with a 500; after app.UseCors() was added the response carried Access-Control-Allow-Origin.
Does UseCors need a policy name when the endpoint uses RequireCors?
Not in the test. app.UseCors() with no argument was enough, because RequireCors("Frontend") on the endpoint named the policy, and the response carried Access-Control-Allow-Origin.

More decoded errors in the Fixes category. The same shape of error for authorization has its own post: 'a middleware was not found that supports authorization'.