RazorLight: DOTNET 6 Error - Cannot find compilation library location for package 'System.Security.Cryptography.Pkcs'

Describe the bug Existing tests fail after upgrade.

To Reproduce Upgrade Test Project from Dotnet 5 to Dotnet 6:

Expected behavior The template should transform

Information (please complete the following information):

Additional context TEST

    public void Convert_GivenValidInput_ShouldConvert()
    {
      // arrange
      Setup();
      var data = new { Name = "TheName" };
      var template = "Name is @Model.Name";

      // action
      var result = _engine.Convert(data, template, true);

      // assert
      result .Should().Be("Name is TheName");
  }

IMPLEMETATION:

        var result = engine.CompileRenderStringAsync(GetTemplateCachedId(templateData), templateData, data,  (ExpandoObject)null).Result;

ERROR:


IIAB.Core.Common.Exceptions.RazorParsingException : One or more errors occurred. (Cannot find compilation library location for package 'System.Security.Cryptography.Pkcs')
   at IIAB.Razor.RazorTemplateEngine.Convert(Object data, String templateData, Boolean ifErrorTrySerializeAndDeserialize) in C:\Git\IIAB-netcore\src\IIAB.Razor\RazorTemplateEngine.cs:line 102
   at IIAB.Razor.Tests.RazorTemplateEngineTests.Convert_GivenValidInput_ShouldConvert() in C:\Git\IIAB-netcore\src\IIAB.Razor.Tests\RazorTemplateEngineTests.cs:line 32

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 95

Most upvoted comments

So for people still having the issue the ultimate solution for this is setting PreserveCompilationContext to true and adding ExcludingAssembly like:

            services.AddRazorLight(() =>
            {
                return new RazorLightEngineBuilder()
                    .UseFileSystemProject(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
                    .UseMemoryCachingProvider()
                    .ExcludeAssemblies(typeof(System.Security.Cryptography.Pkcs.AlgorithmIdentifier).Assembly.GetName().Name) // Workaround for loading CompileLibraries
                    .EnableDebugMode(Debugger.IsAttached)
                    .Build();
            });

If you will try to Exclude Assembly with FullName It will not work. Additonally the RazorLightDependancyEngineBuilder is broken and all ExcludedAssemblies are ignored further in DefaultMetadataReferenceManager. @jzabroski

OK, I see the problem. I forgot I put the version in the src/Directory.Build.props not the top level build props. Should be fixed. It will be published as rc.6 unfortunately

Looks like you’ve been fighting with failures 😔 and the latest failure is because it couldn’t find the project.

I’ve never really dealt with github actions before, but looking at the code here for alirezanet/publish-nuget, I can see that it just references this.projectFile = process.env.INPUT_PROJECT_FILE_PATH whereas the others reference both the environment variable with and without the INPUT_ part. I also spotted this issue where there was a bug where the INPUT_ was being ignored.

Perhaps we need to switch PROJECT_FILE_PATH: src\RazorLight\RazorLight.csproj for INPUT_PROJECT_FILE_PATH: src\RazorLight\RazorLight.csproj temporarily?

@jzabroski Thanks for the quick reply.

I have raised a PR based on the changes from the latest code by @jacodv in https://github.com/jacodv/RazorLightDotNet6/tree/branch_jdevil-Dotnet6-WebApi6

I have excluded some of the extraneous code though.

@jzabroski

Short Answer: I have successfully upgraded to .Net 6 including the latest language version

https://github.com/jacodv/RazorLightDotNet6/tree/branch_jdevil-Dotnet6-Upgrade-RazorLight-Tests Show the code and tests

Running commentary

Please have a look at this readme

https://github.com/jacodv/RazorLightDotNet6/blob/branch_jdevil-Dotnet6-Upgrade-RazorLight-Tests/DotNet6Status/README.md

I have detailed every step to reproduce as well as what must be changed to enable .Net 6

@jzabroski : My Error has todo with a dependency (System.Security.Cryptography.Pkcs) of referenced Nuget packages. It would seem that different Nuget packages depend of different versions of this dependency. I realized it by looking at the project.assets.json file in the obj folder.

I still get the error after making the above changes and referencing the new RazorLight project. If I remove the project that has all the nuget packages it works.

Three questions:

  • Is there a way to for the load of a specific version when the RazorEngine compiles?
  • Why does this only occur when the test project (Entry Assembly) is .Net6?
  • Is there a way to debug and determine which Nuget package causes the error? Bear in mind that the razor template and data does not reference any of the nuget packages, it must happen in the load of the reference assembly.