Open gabynevada opened 2 days ago
Update, with minimal api it works.
The problem appears to be in Controllers:
app.MapGet(
"/minimal-api",
async (
[FromServices] IDataService dataService,
HttpContext httpContext,
CancellationToken cancellationToken
) =>
{
var results = await dataService.GetData();
httpContext.Response.Headers.Append("Test", results.Name);
return results.Data;
}
);
Sadly since it's a legacy app it will take us a while to migrate completely to minimal apis.
https://github.com/dotnet/aspnetcore/pull/57924 will fix this
Is there an existing issue for this?
Describe the bug
Had similar issues on .NET 6 release, adding just in case it's related:
In .Net 9 RC1 when trying to set a header before yielding the first value on an IAsyncEnumerable, I get the following error:
Implementation of Controller looks like this:
Expected Behavior
The header to be set without errors as is possible in .NET 8
Usecase
We use this mostly to set Pagination headers for paginated lists
Steps To Reproduce
Use this webapi minimal reproduction
https://github.com/gabynevada/.net6-iasync-enumerable-set-header-error
Call endpoint returning IAsyncEnumerable
Can replicate both on RC1 and the daily build for RC2
Exceptions (if any)
.NET Version
9.0.100-rc.2.24466.1
Anything else?
IDE: JetBrains Rider 2024.2.4 on Mac M1 Arm 64
dotnet --info: