toddams/RazorLight

Failed to find type or namespace name 'Dictionary'

mirrortom opened this issue · 0 comments

Describe the bug
I'm Learning on razorlight, and when using foreach to traverse the type List<Dictionary<string, string>>, an exception is thrown.

System.AggregateException:“One or more errors occurred. (Failed to compile generated Razor template. "Failed to find type or namespace name 'Dictionary,' (Is a using directive or assembly reference missing?)"

To Reproduce
call the function:
var result = engine.CompileRenderStringAsync(key, templete, dict).Result;

Expected behavior
I think it compiles successfully, Dictionary<string,string> is a .NET type in namespace System.Collections.Generic

Information (please complete the following information):

  • OS: [ Windows 10 ]
  • Platform [.NET 6.0]
  • RazorLight version [ 2.3]
  • Are you using the OFFICIAL RazorLight package? https://www.nuget.org/packages/razorlight // YES
  • Visual Studio version [ Visual Studio Community 17.4.2 ]

Additional context
// init
var engine = new RazorLightEngineBuilder().UseMemoryCachingProvider().Build();

// model data
List<Dictionary<string, string>> model = new();
model.Add(dict1);// add more dict ...

// template
string temp = "@foreach(Dictionary<string,string> dict in Model){<h1>@dict[\"a\"]</h1><h1>@dict[\"b\"]</h1>}";

// run ,exception throw
string result = engine.CompileRenderStringAsync("key1", tmp, dict).Result;