I have an IList<IHtmlString>
to which I want to add some elements. Since short time it throws an ArrayTypeMismatchException
, but I have no idea why. This also happens when adding or accessing elements from 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
}
}
}
Can anybody explain this to me? And why didn't it happen during the last three years? I got the exception the first time after changing from .NET 4.0 to 4.5.
Stack Trace:
at System.Collections.Generic.List`1.Add(T item)
at MyCompany.Web.Mvc.UI.HtmlList.Add(IHtmlString element)
at MyCompany.Web.Mvc.Models.CaptchaExtensions.CaptchaImageElement.ToString()
at 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)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at 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.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at 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.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Page.Render(HtmlTextWriter writer)
at System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer)
at 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(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
IList<IHtmlString>
– Daniel Hilgarth