var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/foo", () => { return Results.File("/foo", "application/octet-strean", "foo"); });
app.Run();
Run the above with a symlink named /foo
in the filesystem, pointing to a real file. When requesting the path, the following exception is produced.
InvalidOperationException: Response Content-Length mismatch: too many bytes written (558 of 13).
Exceptions (if any)
System.InvalidOperationException: Response Content-Length mismatch: too many bytes written (558 of 13).
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.VerifyAndUpdateWrite(Int32 count)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.FirstWriteAsyncInternal(ReadOnlyMemory`1 data, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.WritePipeAsync(ReadOnlyMemory`1 data, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponseStream.WriteAsync(ReadOnlyMemory`1 source, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Http.StreamCopyOperationInternal.CopyToAsync(Stream source, Stream destination, Nullable`1 count, Int32 bufferSize, CancellationToken cancel)
at Microsoft.AspNetCore.Http.SendFileFallback.SendFileAsync(Stream destination, String filePath, Int64 offset, Nullable`1 count, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Http.SendFileResponseExtensions.SendFileAsyncCore(HttpResponse response, String fileName, Int64 offset, Nullable`1 count, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Http.RequestDelegateFactory.ExecuteResultWriteResponse(IResult result, HttpContext httpContext)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
.NET Version
6.0.101
Anything else?
Marry Christmas 🎄
changed the title
Microsoft.AspNetCore.Http.Results.File fails to determine the correct file size of symlinks
Microsoft.AspNetCore.Http.Results.File() fails to determine the correct file size of symlinks
Dec 23, 2021
@anorm what you can do right now, while the fix is not available, is use one of the other Results.File overloads that calculates the file size using different approaches.
File(Stream, String, String, Nullable, EntityTagHeaderValue, Boolean)
File(Byte[], String, String, Boolean, Nullable, EntityTagHeaderValue)
Thanks for contacting us.
We're moving this issue to the .NET 7 Planning
milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.
Using symbolic link APIs on PhysicalFileResult to obtain the real Length and LastModifiedTime
#39330
Using symbolic link APIs on PhysicalFileResult to obtain the real Length and LastModifiedTime
brunolins16/aspnetcore