Skip to content

MissingMethodException: RecyclableMemoryStreamManager.GetStream() #4967

Closed
@0xfeeddeadbeef

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

  1. Create a new ASP.NET Web API project
  2. Add <PackageReference Include="Microsoft.Extensions.Http.Diagnostics" Version="8.2.0" />
  3. Add <PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.0" />
  4. Add a HTTP client with body logging enabled: clientBuilder.AddExtendedHttpClientLogging(x => { x.LogBody = true; });
  5. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

area-telemetrybugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions