Aspnetcore: Calling Request.EnableRewind throw on 3.0.0-preview7

Created on 24 Jul 2019  路  8Comments  路  Source: dotnet/aspnetcore

An ASP.NET Core 3 app calling out to a library which depends on Microsoft.AspNetCore.Hosting 2.x and access HttpContext.Request.EnableRewind() throws an exception.

To Reproduce

I have a repro here: https://github.com/bruno-garcia/aspnetcore3-hosting2.x-enable-rewind-throws

Steps to reproduce the behavior:

  1. .NET SDK 3.0.100-preview7-012821.
  2. Using this version of ASP.NET Core '3.0.0-preview7.19365.7 '
  3. Create a new class library targeting netstandard2.0
  4. Add dependency to Microsoft.AspNetCore.Hosting version 2.2
  5. Call HttpContext.Request.EnableRewind() in it.
  6. Use the library from the ASP.NET Core 3 app

Expected behavior

Request buffering happens

Error:

fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HLOG3BFKK5BS", Request id "0HLOG3BFKK5BS:00000001": An unhandled exception was thrown by the application.
System.TypeLoadException: Could not load type 'Microsoft.AspNetCore.Http.Internal.BufferingHelper' from assembly 'Microsoft.AspNetCore.Http, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
   at Class1.<>c.<<EnableRewind>b__0_0>d.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at Class1.<>c.<EnableRewind>b__0_0(HttpContext context, Func`1 next)
   at Microsoft.AspNetCore.Builder.UseExtensions.<>c__DisplayClass0_1.<Use>b__1(HttpContext context)
   at Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Hosting.HostingApplication.ProcessRequestAsync(Context context)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

Raised here: https://github.com/getsentry/sentry-dotnet/issues/249

In all fairness the extension method in question is under Microsoft.AspNetCore.Http.Internal and even on 2.1 it was also available EnableBuffering. I've replaced the two in the library and it's working properly.

area-servers

Most helpful comment

@sc1994 if I read this correctly you would need to change any calls to EnableRewind to EnableBuffering as shown in the the pull request that sentry committed to fix this in their code. https://github.com/getsentry/sentry-dotnet/pull/250/commits/520bb783761040ce336925a8376ed1e7c0dd31c7

All 8 comments

@davidfowl is this a scenario we still try to support where we have different dependencies to ASP.NET Core?

/cc @Tratcher. Does this need a breaking change announcement?

This is part of the pubternal move to internal. We haven鈥檛 written the uber announcement for that as yet.

@WellspringCS That's related only in that there's a dependency mismatch.

OK, so likely to go away when they release an updated version, I take it.

Closing as this should be fixed when referencing the latest versions.

This problem persists after version 3.0.100-preview8-013656 is specified, with the same error.
Do I need to do more?

@sc1994 if I read this correctly you would need to change any calls to EnableRewind to EnableBuffering as shown in the the pull request that sentry committed to fix this in their code. https://github.com/getsentry/sentry-dotnet/pull/250/commits/520bb783761040ce336925a8376ed1e7c0dd31c7

Was this page helpful?
0 / 5 - 0 ratings