13
votes

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.

2

2 Answers

7
votes

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'.
2
votes

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;
        }