【发布时间】:2015-11-05 13:01:50
【问题描述】:
我正在尝试在类库项目中配置 Postal。为此,我需要配置自定义 EmailService。在 Postal 网页上有一个 sn-p 用于执行此操作:
// Get the path to the directory containing views
var viewsPath = Path.GetFullPath(@"..\..\Views");
var engines = new ViewEngineCollection();
engines.Add(new FileSystemRazorViewEngine(viewsPath));
var service = new EmailService(engines);
(见此处:http://aboutcode.net/postal/outside-aspnet.html)
令人惊讶的是,抛出了以下错误:
发生 System.ArrayTypeMismatchException HResult=-2146233085
消息=试图以不兼容的类型访问元素 大批。来源=mscorlib 堆栈跟踪: 在 System.Collections.Generic.List`1.Insert(Int32 index, T item) InnerException:
准确地说,它是在将FileSystemRazorViewEngine 添加到ViewEngineCollection 时抛出的。 FileSystemRazorViewEngine 派生自 IViewEngine,ViewEngineCollection 派生自 Collection<IViewEngine>。
这里是堆栈跟踪:
mscorlib.dll!System.Collections.Generic.List.Insert(int index, System.__Canon item) + 0x3e 字节
System.Web.Mvc.dll!System.Web.Mvc.ViewEngineCollection.InsertItem(int 索引,System.Web.Mvc.IViewEngine 项)+ 0x89 字节
我无法弄清楚导致异常的原因。
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-4 razorengine postal