不能在RazorEngine中使用MvcHtmlString / IHtmlString

我刚刚开始使用RazorEngine并且在使用静态辅助方法时遇到了绊脚石。 它只为模板生成一个MvcHtmlString / IHtmlString。 当我调用Razor.Parse(…)时

RazorEngine.Templating.TemplateCompilationException : Unable to compile template. Der Typ 'System.Web.IHtmlString' ist in einer nicht referenzierten Assembly definiert. (not referenced) Fügen Sie einen Verweis auf die Assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' hinzu. 

我添加了对System.WebSystem.Web.MvcSystem.Web.WebPages引用。 还尝试将它们添加到cshtml@using System.Web@using System.Web.Mvc )。 但@using System.Web.Mvc导致.MvcSystem.Web不可用?

我正在尝试在NUnit Tests中构建模板。

RazorEngine有一个CompilerServicesUtility类。 这负责在编译视图时加载和制作程序集。 它默认返回当前AppDomain中加载的所有程序集。

对于查看代码的人来说,它有点不直观,但是确保Razor视图编译并且可以使用MvcHtmlString的一种方法是使用AppDomain.Current.Load将System.Web和System.Web.Mvc程序集加载到当前AppDomain中(“”)在执行/编译视图之前。

一个老问题。 @Gopal有正确的答案。 除了添加以下代码,我还必须设置对System.Web的引用以复制本地。

 AppDomain.CurrentDomain.Load("System.Web");