Executing via LinqPad throws "RazorLight.RazorLightException: Can't load metadata reference"
raxuser100 opened this issue · 1 comments
I am using LinqPad which references a ClassLib which in turn executes the RazorLight engine. Physical cshtml
files live in a local folder. I run into the same error:
RazorLight.RazorLightException: Can't load metadata reference from the entry assembly. Make sure PreserveCompilationContext is set to true in *.csproj file
I tried adding <PreserveCompilationContext>
into the classlib csproj, though I know it will not work as it's not the entry point. LinqPad is the entry point!
Attached a simple test linqpad file in the Zip. Also the source code is shown below, just save it as XXX.linq.
Is there any way of getting around this error?
hello_world.cshtml
"Hello, @Model.Name. Welcome to RazorLight repository"
Linq file code:
<Query Kind="Program">
<NuGetReference Prerelease="true">RazorLight.Unofficial</NuGetReference>
<Namespace>RazorLight</Namespace>
<Namespace>System.Threading.Tasks</Namespace>
</Query>
void Main()
{
RazorLightTest().Dump("RazorLight output");
}
public async Task<string> RazorLightTest()
{
var engine = new RazorLightEngineBuilder()
.UseFileSystemProject(@"D:\Temp")
.UseMemoryCachingProvider()
.Build();
var model = new { Name = "John Doe" };
return await engine.CompileRenderAsync("hello_world.cshtml", model);
}
// You can define other methods, fields, classes and namespaces here
Did you try asking Linqpad support? Joseph is very good about supporting people with paid licenses.
I also will note RazorLight.Unofficial isn't supported by this repo.