Razorlight: I get RazorLightException when trying to call lib that contains razor templates from console application

Created on 5 Apr 2017  路  6Comments  路  Source: toddams/RazorLight

Exception text:

RazorLight.RazorLightException: 'Can't load metadata reference from the entry assembly. Make sure preserveCompilationContext is set to true in buildOptions section of project.json or in *.csproj file'

Here is the solution with isolated case:
https://1drv.ms/u/s!AuXjDEud3Cas10ihf9jpraKC316w

Most helpful comment

Add <PreserveCompilationContext>true</PreserveCompilationContext> to the csproj, worked for me!

All 6 comments

I downloaded your project, did not change anything and it runs just fine

I've updated the example:
https://1drv.ms/u/s!AuXjDEud3Cas11GysXD1m7XJR-Sv

changing
<TargetFramework>netcoreapp1.1</TargetFramework>
to
<TargetFramework>netstandard1.6</TargetFramework>
in class lib was the key

@ossaltu, I suspect that you didn't clean the project before rebuilding and trying that again. It was an issue for myself. I've just created the PR to add this warning to README.

Add <PreserveCompilationContext>true</PreserveCompilationContext> to the csproj, worked for me!

Yes, clean rebuild seems to be working

@ossaltu and @toddams I got a same problem.
As @ForNeVeR was mentioned, is really important.
If someone is using Visual Studio Code for development, delete bin and obj folder and then dotnet restore and dotnet build the solution and after dotnet run.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IInvocation picture IInvocation  路  6Comments

diegobrum picture diegobrum  路  5Comments

xxeasterxx picture xxeasterxx  路  5Comments

shobman picture shobman  路  4Comments

WaltDaniels picture WaltDaniels  路  6Comments