adoconnection / RazorEngineCore

.NET6 Razor Template Engine
MIT License
576 stars 85 forks source link

Issues with .NET Standard reference on Linux starting with 2020.9.1 #34

Closed Kaliumhexacyanoferrat closed 3 years ago

Kaliumhexacyanoferrat commented 4 years ago

After updating to version 2020.9.1, I get the following exception when rendering templates:

RazorEngineCore.RazorEngineCompilationException: Unable to compile template: (28,29): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. at RazorEngineCore.RazorEngine.CreateAndCompileToStream(String templateSource, RazorEngineCompilationOptions options) at RazorEngineCore.RazorEngine.Compile[T](String content, Action`1 builderAction)

This happens on Linux only (see this build), the same logic works on Windows as expected (with identical SDK versions etc.).

Do you have an idea how to overcome this issue? I tried to tweak the assembly references, but I suspect the compilation process of the template is missing some .NET Standard reference.

adoconnection commented 4 years ago

Hi, thats probably due to I missed something with references on init. Will recheck it again.

adoconnection commented 3 years ago

did it work on 2020.6.1? there was a pull request to remove netstadrard reference if under linux and it never changed from that time (as I can see) https://github.com/adoconnection/RazorEngineCore/commit/7975beb8035d3ef8b0cea79142d56e597510b8c5#diff-da023b3e46c83993108046dee9e55032

However I have the same error as you do. If I return netstandard reference back, the error dissapears. Im confused.

@daghb does 2020.9.1 work for your linux environment?

Kaliumhexacyanoferrat commented 3 years ago

@adoconnection: It did work on 2020.6.1. As dependabot creates a PR for the new version, I can rule out changes in the environment (such as the SDK version).

adoconnection commented 3 years ago

I have no idea how is this possible :) here are all the changes, 2020.6.1 - is July version https://github.com/adoconnection/RazorEngineCore/commits/master/RazorEngineCore/RazorEngineCompilationOptions.cs

Kaliumhexacyanoferrat commented 3 years ago

I can have a look later on - what does RuntimeInformation.FrameworkDescription evaluate to in you Linux environment? 🤔

adoconnection commented 3 years ago

ok, the mystery revealed. 2020.6.1 release had "wrong code"

image

Kaliumhexacyanoferrat commented 3 years ago

Build with 2020.10.1 works on Windows and Linux. Thank you very much!