【问题标题】:"Attempted to access an element as a type incompatible with the array" thrown during creating a custom EmailService in Postal在 Postal 中创建自定义 EmailService 时抛出“尝试将元素作为与数组不兼容的类型访问”
【发布时间】: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 派生自 IViewEngineViewEngineCollection 派生自 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


    【解决方案1】:

    我遇到了同样的错误。我怀疑 Postal 是用稍微不同版本的 System.Web.Mvc 构建的,导致 ViewEngine 不兼容的主要项目......但我只有邮政的生产二进制文件......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多