Antaris/RazorEngine

Cannot call Engine.Razor.RunCompile twice in application

Opened this issue · 2 comments

i am getting error when i call Engine.Razor.RunCompile twice with two different sql source.

string sql = Engine.Razor.RunCompile(sqlTmplt, Guid.NewGuid().ToString(), null, request);

Error:

Errors while compiling a Template.
Please try the following to solve the situation:

  • If the problem is about missing/invalid references or multiple defines either try to load
    the missing references manually (in the compiling appdomain!) or
    Specify your references manually by providing your own IReferenceResolver implementation.
    See https://antaris.github.io/RazorEngine/ReferenceResolver.html for details.
    Currently all references have to be available as files!
  • If you get 'class' does not contain a definition for 'member':
    try another modelType (for example 'null' to make the model dynamic).
    NOTE: You CANNOT use typeof(dynamic) to make the model dynamic!
    Or try to use static instead of anonymous/dynamic types.
    More details about the error:
  • error: (9, 89) The type 'TemplateBase' exists in both 'RazorEngine.NetCore, Version=0.0.0.0, Culture=neutral, PublicKeyToken=9ee697374c7e744a' and 'RazorEngine, Version=3.2.0.0, Culture=neutral, PublicKeyToken=9ee697374c7e744a'
    • error: (12, 66) 'RazorEngine_fbe26ed1a83842f9af305e68c4bee0c5.ExecuteAsync()': no suitable method found to override
    • error: (14, 12) The name 'WriteLiteral' does not exist in the current context
    • error: (15, 12) The name 'WriteLiteral' does not exist in the current context
      Temporary files of the compilation can be found in (please delete the folder): D:\Users\SHARM22\AppData\Local\Temp\RazorEngine_ilnncvda.d1b
      The template we tried to compile is:
      ------------- START -----------
      select * from TABLE_NAME Where OrderID = @@0
      ------------- END -----------

The generated source code is:
------------- START -----------
//
#pragma warning disable 1591
namespace CompiledRazorTemplates.Dynamic
{
#line hidden
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
internal class RazorEngine_fbe26ed1a83842f9af305e68c4bee0c5 : RazorEngine.Templating.TemplateBase<System.Collections.Generic.IDictionary<System.String, System.Object>>
{
#pragma warning disable 1998
public async override global::System.Threading.Tasks.Task ExecuteAsync()
{
WriteLiteral("select * from TABLE_NAME Where OrderID = ");
WriteLiteral("@0");
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591

------------- END -----------

List of loaded Assemblies:
C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.7\System.Private.CoreLib.dll
Loaded Assembly: D:\Users\SHARM22.dotnet\tools.store\amazon.lambda.testtool-3.1\0.10.1\amazon.lambda.testtool-3.1\0.10.1\tools\netcoreapp3.1\any\Amazon.Lambda.TestTool.WebTester31.dll
Loaded Assembly: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.7\System.Runtime.dll
Loaded Assembly: D:\Users\SHARM22.dotnet\tools.store\amazon.lambda.testtool-3.1\0.10.1\amazon.lambda.testtool-3.1\0.10.1\tools\netcoreapp3.1\any\Amazon.Lambda.TestTool.dll
Loaded Assembly: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.7\System.Runtime.Extensions.dll
Loaded Assembly: C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\3.1.7\Microsoft.AspNetCore.Mvc.Core.dll
Loaded Assembly: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.7\System.Console.dll
Loaded Assembly: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.7\System.Threading.dll
Loaded Assembly: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.7\System.Text.Encoding.Extensions.dll
Loaded Assembly: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.7\System.IO.FileSystem.dll
Loaded Assembly: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.7\System.Diagnostics.Debug.dll
Loaded Assembly: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.7\System.Linq.dll
Loaded Assembly: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.7\System.Memory.dll
Loaded Assembly: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.7\System.Runtime.InteropServices.dll
Loaded Assembly: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.7\System.Collections.dll
Loaded Assembly: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.7\System.Runtime.Loader.dll
.......................................

Did you find what caused the issue. I am running into a similar issue now in Prod.

error: (9, 89) The type 'TemplateBase' exists in both 'RazorEngine.NetCore, Version=0.0.0.0, Culture=neutral, PublicKeyToken=9ee697374c7e744a' and 'RazorEngine, Version=3.2.0.0, Culture=neutral, PublicKeyToken=9ee697374c7e744a'
error: (12, 66) 'RazorEngine_fbe26ed1a83842f9af305e68c4bee0c5.ExecuteAsync()': no suitable method found to override

We found the issue , we had both the dlls present in the deployed folder. causing the issue.

image