Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not load type 'Microsoft.AspNetCore.Http.Internal.BufferingHelper' .Net Core 3.0 #15

Closed
blogcraft opened this issue Sep 25, 2019 · 7 comments
Labels
SDK-AspNetCore Related to .NET Core framework

Comments

@blogcraft
Copy link

Using Net Core 3.0 There is a new error with kisslog 2.4.0

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 KissLog.AspNetCore.WebRequestPropertiesFactory.ReadInputStream(HttpRequest request)
   at KissLog.AspNetCore.WebRequestPropertiesFactory.Create(HttpRequest request)
   at KissLog.AspNetCore.KissLogMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
@catalingavan
Copy link
Owner

Hi @blogcraft,

I will investigate the issue, and I will come back with further details.
If possible, can you provide some details, please:

  1. The error happened after updating the KissLog.AspNetCore NuGet package on an existing application?

  2. Have you updated the application from targeting .NET Core 2.0 to .NET Core 3.0?

  3. Is this a brand new .NET Core 3.0 application, on which you are trying to install KissLog.AspNetCore NuGet

The error is related to 'Microsoft.AspNetCore.Http.Internal.BufferingHelper' type, which might not be available on .NET Core 3.0 anymore.

@blogcraft
Copy link
Author

Hi, thanks for the quick response.

The app Was originally working fine targeting .Net Core 2.2 and KissLog.AspNetCore "1.7.0"

After updating the App to .Net Core 3.0 the app started to fail.
Then I updated KissLog.AspNetCore to 2.4.0 to see if it could solve it, but didn't.

@catalingavan
Copy link
Owner

Thanks.
I will replicate the scenario on an .NET Core 3.0 app

@catalingavan
Copy link
Owner

Hi @blogcraft,

The issue is caused, indeed, by some incompatibility between KissLog.AspNetCore and .NET Core 3.0.
I will create a package update with a fix, but this might take some time.

(More details about this can be found here: dotnet/aspnetcore#12505)

Meanwhile, I suggest a small workaround, just to keep the project running.

KissLog won't log the Request.InputStream value anymore, but it will not raise an exception.

Update Startup.cs ConfigureServices()

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        #region Temporary fix for KissLog .NET Core 3.0 issue
		
        Type type = typeof(KissLog.Internal.InternalHelpers);
        var field = type.GetField("InputStreamContentTypes", BindingFlags.Public | BindingFlags.Static);
        field.SetValue(null, new string[] { });
		
        #endregion
		
        services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
        services.AddScoped<ILogger>((context) =>
		{
            return Logger.Factory.Get();
        });

        services.AddControllersWithViews();
    }
}

Please let me know if this worked for you.

@blogcraft
Copy link
Author

Thanks a lot, the workaround did help!

Looking forward to package update fix when it's available.

@catalingavan catalingavan added the SDK-AspNetCore Related to .NET Core framework label Sep 26, 2019
catalingavan pushed a commit that referenced this issue Sep 26, 2019
Other general improvements
catalingavan added a commit that referenced this issue Sep 26, 2019
- Fixed issue #15
- Added exception handling when trying to read Request/Response stream
@catalingavan
Copy link
Owner

catalingavan commented Sep 26, 2019

Hi @blogcraft

The issue should be fixed now.

Please update the package to KissLog.AspNetCore 2.4.2

Let me know if everything is working properly (don't forget to remove the workaround 😊).

Thanks

@blogcraft
Copy link
Author

Flawless! It works like a charm! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SDK-AspNetCore Related to .NET Core framework
Projects
None yet
Development

No branches or pull requests

2 participants