'Could not load type 'Microsoft.AspNetCore.Http.Internal.BufferingHelper' from assembly 'Microsoft.AspNetCore.Http, Version=3.1.0.0

I am trying to upgrade my API project from .net core 2.2 to .net core 3.1. I get this exception while I try to make the API call.

"Message":"Could not load type 'Microsoft.AspNetCore.Http.Internal.BufferingHelper' from assembly 'Microsoft.AspNetCore.Http, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.","Statuscode":500,"TrackingID":"800000bd-0000-fe00-b63f-84710c7967bb"

I tried the solution on "github"

Please help me fix the issue.



Solution 1:[1]

I know you already tried this solution but I didn't understand what the post meant with (See comment below)

"By referencing the fixed dll instead of the NuGet package it works again."

However:

My Azure Function was using EnableRewind() on the request object in order to make the stream seekable. I did a straight replace with EnableBuffering() and everything worked again.

I'm using Azure Functions v3 with .NET Core 3.1. This was the error I originally received:

Could not load type 'Microsoft.AspNetCore.Http.Internal.BufferingHelper' from assembly 'Microsoft.AspNetCore.Http, Version=3.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

Solution 2:[2]

So I had the exact issue by using the ReadAsStringAsync method. You will notice that the implementation of that uses the EnableRewind method as well. I ended up just making my own version of ReadAsStringAsync. Implementation is below:

public static async Task<string> ReadAsStringAsync(this HttpRequest request)
        {
            request.EnableBuffering();

            string result = null;
            using (var reader = new StreamReader(
                request.Body,
                encoding: Encoding.UTF8,
                detectEncodingFromByteOrderMarks: true,
                bufferSize: 1024,
                leaveOpen: true))
            {
                result = await reader.ReadToEndAsync();
            }

            request.Body.Seek(0, SeekOrigin.Begin);

            return result;
        }

Solution 3:[3]

I got the same issue during mvc project upgrade from .net core 2.1 to 3.1. Upgrade Microsoft.AspNetCore.Authorization and Microsoft.AspNetCore.Authentication.OpenIdConnect to 3.1.22 through NuGet Package Manager, solved the issue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Andrew Backes
Solution 3 Htin Aung