Site icon Ryadel

Cannot find compilation library 'System.Security.Cryptography.Pkcs' - FIX

Visual Studio 2017 - Lost Razor Intellisense and Syntax Highlight - How to Fix it

If you've stumbled upon this post, there's a high chance you're experiencing a rather odd Visual Studio 2022 issue which I had to deal with today.

I was working on a ASP.NET Web Application project that was working just fine - until I tried to change the debug Web Server from IISExpress to IIS. As you probably already know, doing that requires to apply the following changes:

  • Install IIS (you bet!) and manually create the Virtual Application for my project using IIS Manager.
  • Install the IIS Development-time support for Visual Studio, as explained here.
  • Relocate the secrets.json file, assuming you are using the Visual Studio User Secrets feature (read this post for more info on that), as IIS doesn't have the required permissions to read the default folder where Visual Studio creates the secrets.json file.
  • Adding a new IIS profile to the launchSettings.json file with the required settings (applicationUrl, sslPort, etc).

I was already aware of all that, hence I did the above steps without issues.

What I didn't expect was the following error, which occurred right after I launched the project in Debug mode:

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

I struggled a bit on StackOverflow trying to figure out what happened, which helped me to understand that the issue was somewhat related to the Razor Runtime Compilation feature - which works perfectly on IISExpress, but seems to have some odd incompatibilities with IIS.

Unfortunately, the only workaround I found there was to disable that feature - which I really didn't want to since I love it.

Solution

Luckily I found a better fix: I just had to install the System.Security.Cryptography.Pkcs NuGet package, which immediately solved the issue. Yeah, it was just that simple!

This allowed me to keep the Razor Runtime Compilation feature enabled: yay!

Conclusion

I hope this helps other people having this same issue. For further info about this topic, read this StackOverflow thread.

 

Exit mobile version