Describe the bug
In our .net framework web app, targeting .net framework 4.8
To Reproduce
Steps to reproduce the behavior:
await Request.Content.ReadAsMultipartAsync();Expected behavior
I expect APM not to interfere with reading multipart async request streams, especially when we don't have Body capturing enabled.
Here is a stripped down stack trace:
Error reading MIME multipart body part.
System.IO.IOException: Error reading MIME multipart body part. [Source: System.Net.Http.Formatting]
at System.Net.Http.HttpContentMultipartExtensions.d__9`1.MoveNext() --- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at <internal Service>.d__0.MoveNext() in <path to internal service source file>:line 14 --- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at <internal ApiController>.d__8.MoveNext() in <path to internal ApiController source file>:line 77
Inner Exception:
System.InvalidOperationException: Unable to read the entity body in Bufferless mode. The request stream has already been buffered. [Source: System.Web.Http.WebHost]
at System.Web.Http.WebHost.HttpControllerHandler.<>c__DisplayClass18_0.b__1()
at System.Web.Http.WebHost.HttpControllerHandler.LazyStreamContent.get_StreamContent()
at System.Web.Http.WebHost.HttpControllerHandler.LazyStreamContent.CreateContentReadStreamAsync()
at System.Net.Http.HttpContent.ReadAsStreamAsync()
at System.Net.Http.HttpContentMultipartExtensions.d__9`1.MoveNext()
Endpoint example
[Route]
public async Task<IHttpActionResult> Post()
{
var content = await Request.Content.ReadAsMultipartAsync(); //exception gets thrown here
return Ok(content.ToString());
}
Added a reproduction scenario to the sample aspnetframework project:
https://github.com/elastic/apm-agent-dotnet/pull/1114
Thanks for reporting @WillGunn, I've opened https://github.com/elastic/apm-agent-dotnet/pull/1115 to address