首页 新闻 会员 周边

求解:一个奇怪的类型转换问题

0
悬赏园豆:30 [已解决问题] 解决于 2012-03-02 08:52

今天遇到了一个很奇怪的问题,起初页面正常,有时候一动其他页面的代码就会报错;时好时坏!

错误提示如下:

View Code
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",有时候随便动一动就好了,一动别的页面就报错!有人遇到过吗?这是什么原因? 谢谢!

skybirdzw的主页 skybirdzw | 初学一级 | 园豆:3
提问于:2012-02-14 17:04
< >
分享
最佳答案
0

把 

IList<TradeSite.CatInformation.Model.CatInfo_CategoryInfoInfo> CList_1
改成
var CList_1
再看看报什么错。
收获园豆:15
水牛刀刀 | 大侠五级 |园豆:6350 | 2012-02-14 17:39
其他回答(1)
0

应该是类型转换错误,你检查一下他提到的方法。好像你获取的是单个实体,而想把它转为List。

收获园豆:15
LCM | 园豆:6876 (大侠五级) | 2012-02-14 17:10

方法检查过了,没问题啊。返回类型就是IList<T>类型。我怀疑是.NET内部机制搞的鬼,我对.NET研究的不深入,请高手帮忙分析下原因?

支持(0) 反对(0) skybirdzw | 园豆:3 (初学一级) | 2012-02-14 17:14

@skybirdzw: 先别怀疑微软,再检查检查GetOneLevel方法。

支持(0) 反对(0) LCM | 园豆:6876 (大侠五级) | 2012-02-14 17:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册