我有一个IList<IHtmlString>
我想添加一些元素的。由于短时间内它会抛出一个ArrayTypeMismatchException
,但我不知道为什么。从 HttpSessionStateBase 添加或访问元素时也会发生这种情况。
public class HtmlList
{
private IList<IHtmlString> _listItems = new List<IHtmlString>();
public void Add(IHtmlString listItem)
{
if (listItem != null)
{
_listItems.Add(listItem); // here ArrayTypeMismatchException is thrown
}
}
}
有人可以向我解释一下吗?为什么过去三年没有发生这种情况?从 .NET 4.0 更改为 4.5 后,我第一次遇到异常。
堆栈跟踪:
在 System.Collections.Generic.List`1.Add(T item)
在 MyCompany.Web.Mvc.UI.HtmlList.Add(IHtmlString element)
在 MyCompany.Web.Mvc.Models.CaptchaExtensions.CaptchaImageElement.ToString()
在 MyCompany .Web.Mvc.Models.CaptchaExtensions.CaptchaImageElement.Render(Int32 width, Int32 height)
at ASP.views_teilnahme_index_aspx.__RenderContent3(HtmlTextWriter __w, Control parameterContainer)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
在 System.Web.UI.Control.Render(HtmlTextWriter writer)
在 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter 适配器)
在 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
在 System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
在 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
在 System .Web.UI.Control.RenderChildren(HtmlTextWriter writer)
在
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)在 System.Web.UI.Control.Render(HtmlTextWriter writer)
在 System.Web.UI。 Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
在 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
在 System.Web.UI.Page.Render(HtmlTextWriter writer)
在 System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer)
在 System.Web.UI.Control .RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Page.ProcessRequestMain (布尔型 includeStagesBeforeAsyncPoint,布尔型 includeStagesAfterAsyncPoint)