[A]List`1[MyObject] cannot be cast to [B]List`1[MyObject]
2024-10-08 14:19:48
Description I have created a small class in a single ASP.NET 4.5 web forms page that is instantiated and then stored in a List, then saved/loaded from ViewState: <Serializable>
Private Class _PageLevelToolTip
Public ClientId As String
Public TipText As String
End Class Private Property _pageLevelToolTipCollection As List(Of _PageLevelToolTip)
Get
Return ViewState("_toolTipCollection")
End Get
Set(value As List(Of _PageLevelToolTip))
ViewState("_toolTipCollection") = value
End Set
End Property This class only appears on one page in the whole application.
Users are reporting an intermittent error on subsequent page loads: [A]System.Collections.Generic.List1[selfassessment+_PageLevelToolTip] cannot be cast to [B]System.Collections.Generic.List1[selfassessment+_PageLevelToolTip]. Type A originates from 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Type B originates from 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. After searching for days I found a tip that seems to solve the issue, by casting to the type explicitly: Private Property _pageLevelToolTipCollection As List(Of _PageLevelToolTip)
Get
Return CType(ViewState("_toolTipCollection"), List(Of _PageLevelToolTip)) ' Revision here '
End Get
' Setter removed for brevity '
End Property Is this a bug?
We cannot test this accurately because of the wildly intermittent nature. This is a page-level private object and list that only exist in a single page. Although the error does not trigger in the above manner, I can recreate it by doing the following process: . Load page (ensuring class is saved within viewstate)
. Edit page in VS and save
. Load page (to load class from Viewstate) This would imply that the object changes in some way part-way through postbacks, although it's structure does not, or the compiled page changes and won't recognise the original. I hope this helps in the diagnosis. Another person is reporting the same fault from a different approach, but the answer given does not help here: https://connect.microsoft.com/VisualStudio/feedback/details/779108/xaml-designer-in-vs2012-throws-invalidcastexception
來源:http://cncc.bingj.com/cache.aspx?q=%5bA%5dSystem.Collections.Generic.List+cannot+be+cast+to+%5bB%5dSystem.Collections.Generic.List&d=4976373898546130&mkt=zh-CN&setlang=zh-CN&w=p1PWhpihlQ3W_kwkM-AEL10hUnZb69sm
最新文章
- odoo server命令行以及配置文件
- [C#基础知识] ReadOnly关键字修饰的变量可以修改,只是不能重新分配
- iOS 日常工作之常用宏定义大全
- 3.3 SQLite数据库
- CentOS5.5上安装git
- css3 在线编辑工具 连兼容都写好了
- maven spring mybatis配置注意点
- C++如何返回不定长数组
- linux基础命令--userdel 删除用户帐户和相关文件
- IO流(一)
- 02:安装 Kerberos
- 有关Web常用字体的研究?
- LOJ.6235.区间素数个数(Min_25筛)
- str、tuple、dict之间的相互转换
- 【Codeforces 1110D】Jongmah
- ES6的相关信息
- input上传限定文件类型
- leftJoin鏈錶查詢
- win8.1系统vs2013中boost 1.55.0的安装
- 云端中间层负载均衡工具 Eureka
热门文章
- IntelliJ IDEA 2017.3尚硅谷-----设置项目文件编码
- AcWing 240. 食物链
- rancher 方式创建nfs-client 存储类流程
- 最小树形图模板 UVA11183
- Caffe 笔记 (一)caffe的层与数据结构
- 【PAT甲级】1109 Group Photo (25分)(模拟)
- Good Bye 2019E(点坐标缩小一半以区分奇偶性)
- ALSA lib基本概念
- 每天进步一点点------如何实现Sobel Edge Detector? (Image Processing) (C/C++)
- JavaScript - what is ";this";? this是什么?