RazorLight icon indicating copy to clipboard operation
RazorLight copied to clipboard

An exception of type 'System.ArgumentNullException' occurred in RazorLight.dll but was not handled in user code: 'Value cannot be null.'

Open kulashaker30 opened this issue 6 years ago • 11 comments

When running this line of codes in .net core 3 (mac) I got this exception (👆)

var engine = new RazorLightEngineBuilder().UseMemoryCachingProvider().Build();

I am new to this RazorLight so apology if this exception is kinda obvious to some folks if not most.

kulashaker30 avatar Dec 06 '19 04:12 kulashaker30

me too,

Value cannot be null. 
razorLightProject
   at RazorLight.Compilation.RazorTemplateCompiler..ctor(RazorSourceGenerator sourceGenerator, RoslynCompilationService roslynCompilationService, RazorLightProject razorLightProject, RazorLightOptions razorLightOptions)
   at RazorLight.RazorLightEngineBuilder.Build()

one-matrix avatar Dec 06 '19 10:12 one-matrix

me too,

Value cannot be null. 
razorLightProject
   at RazorLight.Compilation.RazorTemplateCompiler..ctor(RazorSourceGenerator sourceGenerator, RoslynCompilationService roslynCompilationService, RazorLightProject razorLightProject, RazorLightOptions razorLightOptions)
   at RazorLight.RazorLightEngineBuilder.Build()

@one-matrix I got help from this issue. Please read the conversation I had from the bottom of the thread. Also, I changed from version 2.0.0-beta2 TO 2.0.0-beta1.

kulashaker30 avatar Dec 06 '19 11:12 kulashaker30

@one-matrix @kulashaker30 I can confirm that rolling back to 2.0.0-beta1solved this issue for me too.

K-Cyganiak avatar Dec 06 '19 15:12 K-Cyganiak

It seems this issue is documented here: https://nicedoc.io/dotnet/core/blob/master/release-notes/3.0/preview/3.0.0-preview-known-issues.md#preview-3

  • [RESOLVED] Runtime compilation using Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation throws an error stating "Cannot find reference assembly": When performing runtime Razor compilation, the application throws an error stating reference assemblies cannot be found. To workaround this, edit the project file and add this following property:
<PropertyGroup>
  <PreserveCompilationReferences>true</PreserveCompilationReferences>
</PropertyGroup>

@kulashaker30 Are you saying if you use 2.0.0-beta2 and <PreserveCompilationReferences>true</PreserveCompilationReferences> the problem is not fixed? I'm a little confused on what you did vs. didn't try.

jzabroski avatar Dec 06 '19 15:12 jzabroski

It seems this issue is documented here: https://nicedoc.io/dotnet/core/blob/master/release-notes/3.0/preview/3.0.0-preview-known-issues.md#preview-3

  • [RESOLVED] Runtime compilation using Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation throws an error stating "Cannot find reference assembly": When performing runtime Razor compilation, the application throws an error stating reference assemblies cannot be found. To workaround this, edit the project file and add this following property:
<PropertyGroup>
  <PreserveCompilationReferences>true</PreserveCompilationReferences>
</PropertyGroup>

@kulashaker30 Are you saying if you use 2.0.0-beta2 and <PreserveCompilationReferences>true</PreserveCompilationReferences> the problem is not fixed? I'm a little confused on what you did vs. didn't try.

@jzabroski Yes, adding <PreserveCompilationReferences>true</PreserveCompilationReferences> this in the project file doesn't resolve the issue, unless I use version 2.0.0-beta1

kulashaker30 avatar Dec 06 '19 15:12 kulashaker30

@kulashaker30 What if you add both PreserveCompilationContext and PreserveCompilationReferences? https://github.com/dotnet/sdk/pull/2800

These knobs drive me insane.

jzabroski avatar Dec 06 '19 15:12 jzabroski

@jzabroski <PropertyGroup> <PreserveCompilationReferences>true</PreserveCompilationReferences> </PropertyGroup> Yes, those. but no luck, @one-matrix confirmed the work around.

kulashaker30 avatar Dec 06 '19 15:12 kulashaker30

I have the same problem with .NET Core 2.2. Right now I solved the issue by adding UseFileSystemProject and pointing to an empty folder:

var engine = new RazorLightEngineBuilder() .UseFileSystemProject("/TEMP~EMPTY") .UseMemoryCachingProvider() .Build();

marcellorutter avatar Dec 06 '19 17:12 marcellorutter

I have the same problem with .NET Core 2.2. Right now I solved the issue by adding UseFileSystemProject and pointing to an empty folder:

var engine = new RazorLightEngineBuilder() .UseFileSystemProject("/TEMP~EMPTY") .UseMemoryCachingProvider() .Build();

@mrutter We encountered the problem in .net core 3 and version 2.0.0-beta2.

kulashaker30 avatar Dec 06 '19 17:12 kulashaker30

The fix for this is to add a sensible default in RazorLightEngineBuilder. Either FileSystemRazorProject or EmbeddedResourceRazorProject don't really make sense to me. We should create a NoRazorProject that throws if you use its features.

jzabroski avatar Jan 04 '21 23:01 jzabroski

Fixed. I realized that a lot of people probably got code either from an old README.md or from https://dontpaniclabs.com/blog/post/2018/08/08/using-razor-templates-without-mvc-razorlight/ so I decided the best thing to do here was to default to using dynamic templates if you don't pick a project.

jzabroski avatar Jan 06 '21 01:01 jzabroski