2

I am getting this error (System.IO.FileLoadException: 'Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401)') when running my C# MVC solution targeting .Net Framework 4.7 in Visual Studio 2019 V16.11.13.

This error is occurring on my Startup.cs (See the piece of code with ** ** this is where the error is occurring):

public void Configuration(IAppBuilder app)
    {
        app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

        bootstrapper.Initialize(CreateKernel);

        HttpConfiguration config = new HttpConfiguration();

        config.DependencyResolver = new NinjectResolver(bootstrapper.Kernel);

        config.MapHttpAttributeRoutes();

        config.EnableSwagger(c =>
        {
            c.Schemes(new[] { "https" });
            c.SingleApiVersion("v1", "xxx");
            c.PrettyPrint();
        }).EnableSwaggerUi(c => { c.SupportedSubmitMethods(); });

        ConfigureAuth(app);

        app.UseWebApi(config);
    }

    private static IKernel CreateKernel()
    {
        **var kernel = new StandardKernel(modules);**
        try
        {
            kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
            kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();

            RegisterServices(kernel);
            return kernel;
        }
        catch
        {
            kernel.Dispose();
            throw;
        }
    }

I have tried all solutions found on the web and still not getting a resolution including adding the DWord LoaderOptimization with a value of 1 in my Registry.

LeeneshK
  • 27
  • 5

1 Answers1

1

Try the following fixes in web.config:

<system.web>
...
<trust level="Full" />
</system.web>

Or set legacyCasModel="false"

If it isn’t the issue, there is a similar question that may cause this issue, and a supported hotfix is now available, you can refer to it for more information.

Jiale Xue - MSFT
  • 3,560
  • 1
  • 6
  • 21