toddams / RazorLight

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

Failed to find type or namespace name 'Dictionary' #513

Closed mirrortom closed 1 year ago

mirrortom commented 1 year ago

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):

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;