toddams / RazorLight

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

Using RazorLight from a .NET Framework assembly loaded via Assembly.LoadFile crashes #282

Closed RedX2501 closed 4 years ago

RedX2501 commented 4 years ago

Using latest master (60fdee0b937233d201f8c57410e6ee5a02b2dffc).

When using RazorLight from an assembly loaded via Assembly.LoadFile the following error is raised:

'Cannot find compilation library location for package 'MyTemplateGenerator''

I have created a sample project with which the problem can be reproduced. It is a WPF .NET Framework 4.7.2 application that loads a .NET Standard 2.0 assembly that uses RazorLight. See class SomeViewModel.cs for the loading and calling of the plugin.

RarzorLightAsPlugin.zip

jzabroski commented 4 years ago

I am just curious - if you load the Assembly via deps.json, do you still get the same problem? I've been meaning to more carefully understand .NET Core assembly loading.

RedX2501 commented 4 years ago

I'm sorry but deps.json files are for core projects. I don't think .Net framework has any support for it.

jzabroski commented 4 years ago

I haven't looked into this but have you thought about upgrading to .NET Core 3.0 https://docs.microsoft.com/en-us/dotnet/desktop-wpf/migration/convert-project-from-net-framework

jzabroski commented 4 years ago

A bit of a hack, but if you stand up RazorLight as a web server, you can talk to it from your WPF app that way.

I need to still investigate this.

jzabroski commented 4 years ago

As an update here: I think the issues is that while .netstandard2.0 technically supports "legacy .NET Framework" e.g. #if NETFRAMEWORK, ASP.NET Core does not. As such, there are no assemblies directly available to link against safely. Recommendation remains to spin up a separate dotnet.exe .NET Core process and use IPC instead. You can build a simple IPC messaging protocol on top of Octopus Deploy's Halibut runtime.