toddams / RazorLight

Template engine based on Microsoft's Razor parsing engine for .NET Core
Apache License 2.0
1.51k stars 260 forks source link

missing Antlr3.Runtime, Version=3.1.3.22795, Culture=neutral, PublicKeyToken=null #323

Closed pomarc closed 4 years ago

pomarc commented 4 years ago

when running my WPF, .NET Framework 4.7.2 application, the call to

  string result = engine.CompileRenderStringAsync(Guid.NewGuid().ToString(), 
                template.Content,
                Model
            ).Result;

throws FileLoadException, can't load 'Antlr3.Runtime, Version=3.1.3.22795, Culture=neutral, PublicKeyToken=null or one of its deps.

the above code is on a .net standard 2.0 class library, referenced by the main application. the class library works fine when called from an xUnit unit test. the version of razorlight is 2.0.0-beta4

explicitly calling Install-Package Antlr.Runtime -Version=3.1.3.22795 succeeds in the class library but fails on the app. installing the latest antlr.runtime on the app succeeds but the crash still remains.

jzabroski commented 4 years ago

Did you use the PreserveCompilationContext settings ? What version of msbuild/dotnet are you using to build/pack your net472 app? Are you using csproj legacy format or csproj SDK format?

jzabroski commented 4 years ago

https://github.com/toddams/RazorLight#im-getting-cannot-find-reference-assembly-microsoftaspnetcoreantiforgerydll-exception-on-net-core-app-30-or-higher

pomarc commented 4 years ago

Did you use the PreserveCompilationContext settings ?

yep, to no avail.

What version of msbuild/dotnet are you using to build/pack your net472 app?

I use vs 2019, msbuild 16.4.0.56107

Are you using csproj legacy format or csproj SDK format?

legacy, <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

jzabroski commented 4 years ago

Please use modern project file format and let me know if that fixes things. If you're not using PackageReference syntax, you cant generate a .deps.json and can't tell the .NET runtime how to interpret all your dependencies. While I'm sure you can get this to work by manually loading the right assemblies, it seems like a lot of dirty work vs just moving to the new project file format.

If you haven't moved yet and the reason is due to wanting to host this in a strange context, let's discuss.

net472 tfm doesn't fully support .NET Standard 2.0, so I'm not surprised this might have problems somewhere in the dependency tree. The simplest solution would be to have your WPF UI talk IPC to a service that runs in the background that manages these things. - That background service would likely be a .netcoreapp2.1 application running .net core runtime 2.2. For simple IPC, I recommend considering Octopus Deploy's Halibut abstraction, as it avoids much of the bad design of .NET Remoting: https://www.nuget.org/packages/Halibut/