Cryptc
Cryptc

Reputation: 3595

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

Upvotes: 5

Views: 3004

Answers (4)

Jim Speaker
Jim Speaker

Reputation: 1332

I upgrade a Web App from .NET 6 to .NET 8 and ran into the same issue - precisely the same error message.

I updated Nuget packages related to Microsoft.AspNetCore (components, razor runtime, etc.) to the latest version 8 (8.0.11 at this time), and as suggest by @Darkseal I also added the System.Security.Cryptography.Pkcs version 8.0.1.

This resolved the issue.

Nuget Package Manager Screenshot

Upvotes: 0

Darkseal
Darkseal

Reputation: 9564

I'm a bit late to the party, however, I just experienced this issue right after I changed the Development Web Server from IISExpress to IIS in a .NET6 project.

In order to fix it, I just had to install the System.Security.Cryptography.Pkcs NuGet Package.

This allowed me to keep the Razor Runtime Compilation feature enabled, which I didn't want to lose.

I hope this helps other people having this same issue. For further info about this topic, read this post on my blog.

Upvotes: 2

Cryptc
Cryptc

Reputation: 3595

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

Upvotes: 7

Shakermaker
Shakermaker

Reputation: 174

I get this error only when running application (piranha cms) inside docker container. I had to remove razor runtime compilation to make it work.

// comment out or delete this line
// options.AddRazorRuntimeCompilation = true;

Upvotes: 0

Related Questions