今天遇到了一个很奇怪的问题,起初页面正常,有时候一动其他页面的代码就会报错;时好时坏!
错误提示如下:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Unable to cast object of type 'TradeSite.CatInformation.Model.CatInfo_CategoryInfoInfo' to type 'System.Collections.Generic.IList`1[TradeSite.CatInformation.Model.CatInfo_CategoryInfoInfo]'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Unable to cast object of type 'TradeSite.CatInformation.Model.CatInfo_CategoryInfoInfo' to type 'System.Collections.Generic.IList`1[TradeSite.CatInformation.Model.CatInfo_CategoryInfoInfo]'.
Source Error:
Line 66: protected void BindCategory()
Line 67: {
Line 68: IList<TradeSite.CatInformation.Model.CatInfo_CategoryInfoInfo> CList_1 = TradeSite.CatInformation.BLL.CatInfo_CategoryInfo.GetOneLevel();
Line 69: if (CList_1 != null && CList_1.Count > 0)
Line 70: {
Source File: d:\web\fenlei.yanshi.b2b.cn\CatInformation\Module\CategoryInfoListModule201.ascx Line: 68
Stack Trace:
[InvalidCastException: Unable to cast object of type 'TradeSite.CatInformation.Model.CatInfo_CategoryInfoInfo' to type 'System.Collections.Generic.IList`1[TradeSite.CatInformation.Model.CatInfo_CategoryInfoInfo]'.]
TradeSite.CatInformation.BLL.CatInfo_CategoryInfo.GetOneLevel() +99
ASP.catinformation_module_categoryinfolistmodule201_ascx.BindCategory() in d:\web\fenlei.yanshi.b2b.cn\CatInformation\Module\CategoryInfoListModule201.ascx:68
ASP.catinformation_module_categoryinfolistmodule201_ascx.Page_Load(Object sender, EventArgs e) in d:\web\fenlei.yanshi.b2b.cn\CatInformation\Module\CategoryInfoListModule201.ascx:22
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
提示IList类转换问题,可是语法都没错的!而且我又引用了"System.Collections.Generic",有时候随便动一动就好了,一动别的页面就报错!有人遇到过吗?这是什么原因? 谢谢!
把
IList<TradeSite.CatInformation.Model.CatInfo_CategoryInfoInfo> CList_1
改成
var CList_1
再看看报什么错。
应该是类型转换错误,你检查一下他提到的方法。好像你获取的是单个实体,而想把它转为List。
方法检查过了,没问题啊。返回类型就是IList<T>类型。我怀疑是.NET内部机制搞的鬼,我对.NET研究的不深入,请高手帮忙分析下原因?
@skybirdzw: 先别怀疑微软,再检查检查GetOneLevel方法。