Search code examples
c#asp.net-mvc.net-6.0

When upgrading to .NET 6, Web Project throws runtime exception


Using an existing .NET 5 MVC Web App, I attempted to upgrade to .NET 6, but encountered this error. I am also using IIS for Windows Authentication--now setup in .NET 6 as "profiles" under Properties -> Debug -> hyperlink (Open debug launch profiles UI). I also included the newer "Microsoft.AspNetCore.Authentication.Negotiate" Nuget package (and associated code) to handle the newer Windows Authentication library.

When the web app launches, I get the following error:

An unhandled exception occurred while processing the request.

InvalidOperationException: Cannot find compilation library location for package 'System.Security.Cryptography.Pkcs'

Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths(ICompilationAssemblyResolver resolver, List assemblies) Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths() Microsoft.AspNetCore.Mvc.ApplicationParts.AssemblyPartExtensions+<>c.b__0_0(CompilationLibrary library) System.Linq.Enumerable+SelectManySingleSelectorIterator<TSource, TResult>.MoveNext()

...

Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

This does NOT go away if I add the package listed: System.Security.Cryptography.Pkcs


Solution

  • I needed to remove at least 1 Nuget package:

    1. Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation -- I removed this one second, but it started working after I did.
    2. Microsoft.Extensions.Hosting -- I removed this one first, but this alone did not fix it. I don't know if this "also" needed to be removed. I assume not, but I'm including, just in case. Removing it did not hurt anything.

    Edit: As a WARNING, this will lose the abilities given by Razor.RuntimeCompilation. However, there appears to be a code incompatibility with, I believe, IIS and Razor in .NET 6.

    Microsoft.AspNetCore.Mvc>Razor.RuntimeCompilation