v4.5RC - InvalidOperationException: Cannot find compilation library location for package 'System.Security.Cryptography.Pkcs'

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
2 years ago
Trying to run v4.5RC in IIS using VS 2022
Works fine using IIS Express but when I try to run in IIS I get the Error

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

Tried cleaning and rebuilding the solution

Full Error
Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths(ICompilationAssemblyResolver resolver, List<string> assemblies)
Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths()
Microsoft.AspNetCore.Mvc.ApplicationParts.AssemblyPartExtensions+<>c.<GetReferencePaths>b__0_0(CompilationLibrary library)
System.Linq.Enumerable+SelectManySingleSelectorIterator<TSource, TResult>.MoveNext()
System.Collections.Generic.List<T>.InsertRange(int index, IEnumerable<T> collection)
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.RazorReferenceManager.GetReferencePaths()
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.RazorReferenceManager.GetCompilationReferences()
System.Threading.LazyInitializer.EnsureInitializedCore<T>(ref T target, ref bool initialized, ref object syncLock, Func<T> valueFactory)
System.Threading.LazyInitializer.EnsureInitialized<T>(ref T target, ref bool initialized, ref object syncLock, Func<T> valueFactory)
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.RazorReferenceManager.get_CompilationReferences()
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.LazyMetadataReferenceFeature.get_References()
Microsoft.CodeAnalysis.Razor.CompilationTagHelperFeature.GetDescriptors()
Microsoft.AspNetCore.Razor.Language.DefaultRazorTagHelperBinderPhase.ExecuteCore(RazorCodeDocument codeDocument)
Microsoft.AspNetCore.Razor.Language.RazorEnginePhaseBase.Execute(RazorCodeDocument codeDocument)
Microsoft.AspNetCore.Razor.Language.DefaultRazorEngine.Process(RazorCodeDocument document)
Microsoft.AspNetCore.Razor.Language.DefaultRazorProjectEngine.ProcessCore(RazorCodeDocument codeDocument)
Microsoft.AspNetCore.Razor.Language.RazorProjectEngine.Process(RazorProjectItem projectItem)
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.RuntimeViewCompiler.CompileAndEmit(string relativePath)
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.RuntimeViewCompiler.OnCacheMiss(string normalizedPath)
Microsoft.AspNetCore.Mvc.Razor.Compilation.DefaultRazorPageFactoryProvider.CreateFactory(string relativePath)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.CreateCacheResult(HashSet<IChangeToken> expirationTokens, string relativePath, bool isMainPage)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.OnCacheMiss(ViewLocationExpanderContext expanderContext, ViewLocationCacheKey cacheKey)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.LocatePageFromViewLocations(ActionContext actionContext, string pageName, bool isMainPage)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.FindView(ActionContext context, string viewName, bool isMainPage)
Microsoft.AspNetCore.Mvc.ViewEngines.CompositeViewEngine.FindView(ActionContext context, string viewName, bool isMainPage)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.FindView(ActionContext actionContext, ViewResult viewResult)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0<TFilter, TFilterAsync>(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext<TFilter, TFilterAsync>(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
StackExchange.Profiling.MiniProfilerMiddleware.Invoke(HttpContext context) in MiniProfilerMiddleware.cs
Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
Nop.Services.Installation.InstallUrlMiddleware.InvokeAsync(HttpContext context, IWebHelper webHelper) in InstallUrlMiddleware.cs
Nop.Services.Common.KeepAliveMiddleware.InvokeAsync(HttpContext context, IWebHelper webHelper) in KeepAliveMiddleware.cs
Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.InvokeCore(HttpContext context)
Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.HandleException(HttpContext context, ExceptionDispatchInfo edi)
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
2 years ago
Hi, Yidna.

We do not use the System.Security.Cryptography.Pkcs library in our project either explicitly or indirectly. If you added it to your project, then make sure that it is correctly copied when building the solution, if you don’t have this library, then, please, try this solution.


Yidna wrote:
Trying to run v4.5RC in IIS using VS 2022
Works fine using IIS Express but when I try to run in IIS I get the Error

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

Tried cleaning and rebuilding the solution
2 years ago
I did not add it
I am using the standard v4.5 RC download and not adding anything
So I dont know where it is coming from

When I search the Solution for   System.Security.Cryptography.Pkcs

I see it in a bunch of files for e.g.
nopCommerce_4.50.0_Source\src\Presentation\Nop.Web\Plugins\DiscountRules.CustomerRoles\Nop.Plugin.DiscountRules.CustomerRoles.deps.json

I see details like

"MimeKit/2.15.0": {
        "dependencies": {
          "Portable.BouncyCastle": "1.8.10",
          "System.Buffers": "4.5.1",
          "System.Reflection.TypeExtensions": "4.7.0",
          "System.Security.Cryptography.Pkcs": "5.0.0",
          "System.Text.Encoding.CodePages": "5.0.0"
        },

Yes when I add the file  System.Security.Cryptography.Pkcs.dll to the \bin directory it is fixed
2 years ago
It is possible that the problem is in the process of building the project, try rebuilding the solution in the release mode, since this library is present in our assembly without source codes

Yidna wrote:
I did not add it
I am using the standard v4.5 RC download and not adding anything
So I dont know where it is coming from

When I search the Solution for   System.Security.Cryptography.Pkcs

I see it in a bunch of files for e.g.
nopCommerce_4.50.0_Source\src\Presentation\Nop.Web\Plugins\DiscountRules.CustomerRoles\Nop.Plugin.DiscountRules.CustomerRoles.deps.json

I see details like

"MimeKit/2.15.0": {
        "dependencies": {
          "Portable.BouncyCastle": "1.8.10",
          "System.Buffers": "4.5.1",
          "System.Reflection.TypeExtensions": "4.7.0",
          "System.Security.Cryptography.Pkcs": "5.0.0",
          "System.Text.Encoding.CodePages": "5.0.0"
        },

Yes when I add the file  System.Security.Cryptography.Pkcs.dll to the \bin directory it is fixed
2 years ago
Building and running in Release does not fix the problem
Strangely when you publish the solution the System.Security.Cryptography.Pkcs file ends up in the refs directory in the published solution
So it’s definitely something to do with the build process related to using IIS
As I said it works fine in IIS Express
2 years ago
Yidna wrote:
Building and running in Release does not fix the problem
Strangely when you publish the solution the System.Security.Cryptography.Pkcs file ends up in the refs directory in the published solution
So it’s definitely something to do with the build process related to using IIS
As I said it works fine in IIS Express


I have the same issue, did you manage to fix this?
2 years ago
I downloaded the System.Security.Cryptography.Pkcs NuGet Package
Then manually copied the bin File to the Bin Directory
2 years ago
Yidna wrote:
I downloaded the System.Security.Cryptography.Pkcs NuGet Package
Then manually copied the bin File to the Bin Directory


Are you using VS2022 preview or the released one?
2 years ago
Microsoft Visual Studio Community 2022 (64-bit)
Version 17.0.5

But did not need to do it for v4.5 Release
2 years ago
I resolved it by adding
<GenerateRuntimeConfigDevFile>true</GenerateRuntimeConfigDevFile>

to the csproj file.

See this StackOverflow Post https://stackoverflow.com/a/70741481/64466
and this GitHub Issue https://github.com/dotnet/aspnetcore/issues/38892
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.