MissingMethodException: RecyclableMemoryStreamManager.GetStream() #4967
Closed
Description
Description
When a project that is using Microsoft.Extensions.Http.Diagnostics
has a direct dependency on version 3.0.0 of Microsoft.IO.RecyclableMemoryStream package and you try to use AddExtendedHttpClientLogging
with body content logging enabled, it will fail with MissingMethodException: RecyclableMemoryStreamManager.GetStream()
.
Reproduction Steps
- Create a new ASP.NET Web API project
- Add
<PackageReference Include="Microsoft.Extensions.Http.Diagnostics" Version="8.2.0" />
- Add
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.0" />
- Add a HTTP client with body logging enabled:
clientBuilder.AddExtendedHttpClientLogging(x => { x.LogBody = true; });
- Send a request using this HTTP client
Expected behavior
HTTP request and response bodies are logged without any errors.
Actual behavior
An error occurred while reading the response data to fill the logger context for request: {http.request.method} {server.address}/{url.path} <s:Microsoft.Extensions.Http.Logging.HttpClientLogger>
System.MissingMethodException: Method not found: 'System.IO.MemoryStream Microsoft.IO.RecyclableMemoryStreamManager.GetStream()'.
at Microsoft.Extensions.Http.Logging.Internal.HttpResponseBodyReader.ReadFromStreamAsync(HttpResponseMessage response, Int32 readSizeLimit, RecyclableMemoryStreamManager streamManager, CancellationToken cancellationToken)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at Microsoft.Extensions.Http.Logging.Internal.HttpResponseBodyReader.ReadFromStreamAsync(HttpResponseMessage response, Int32 readSizeLimit, RecyclableMemoryStreamManager streamManager, CancellationToken cancellationToken)
at Microsoft.Extensions.Http.Logging.Internal.HttpResponseBodyReader.ReadFromStreamWithTimeoutAsync(HttpResponseMessage response, TimeSpan readTimeout, Int32 readSizeLimit, RecyclableMemoryStreamManager streamManager, CancellationToken cancellationToken)
at Microsoft.Extensions.Http.Logging.Internal.HttpRequestReader.ReadResponseAsync(LogRecord logRecord, HttpResponseMessage response, List`1 responseHeadersBuffer, CancellationToken cancellationToken)
at Microsoft.Extensions.Http.Logging.HttpClientLogger.LogResponseAsync(Object context, HttpRequestMessage request, HttpResponseMessage response, Exception exception, TimeSpan elapsed, CancellationToken cancellationToken)
Regression?
No response
Known Workarounds
Use 2.x versions of Microsoft.IO.RecyclableMemoryStream package:
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.3.2" />
Configuration
No response
Other information
No response
Activity