我正在尝试在类库项目中配置 Postal。为此,我需要配置自定义 EmailService。在邮政网页上有一个片段可以做到这一点:
// 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
消息=尝试以与数组不兼容的类型访问元素。Source=mscorlib StackTrace:在 System.Collections.Generic.List`1.Insert(Int32 索引,T 项) InnerException:
准确地说 - 它是在添加FileSystemRazorViewEngine
到ViewEngineCollection
. FileSystemRazorViewEngine
源自IViewEngine
和ViewEngineCollection
源自Collection<IViewEngine>
。
这是堆栈跟踪:
mscorlib.dll!System.Collections.Generic.List.Insert(int index, System.__Canon item) + 0x3e bytes
System.Web.Mvc.dll!System.Web.Mvc.ViewEngineCollection.InsertItem(int index, System.Web.Mvc.IViewEngine item) + 0x89 bytes
我无法弄清楚导致异常的原因。