[A]List`1[MyObject] cannot be cast to [B]List`1[MyObject]
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
[A]List`1[MyObject] cannot be cast to [B]List`1[MyObject]的更多相关文章
- initialize myObject by calling a function that returns an object literal
w作用域控制变量的可见范围. JavaScript: The Good Parts Instead of initializing myObject with an object literal, w ...
- WinPhone学习笔记(四)——磁贴
对每个Windows Phone的使用者来说,给他们的第一印象就是大大小小的磁贴——Metro,本篇介绍的是Windows Phone的磁贴,提到的有开始菜单的磁贴,也有在App里面的磁贴. 开始菜单 ...
- 词频统计_输入到文件_update
/* 输入文件见337.in.txt 输出文件见338.out.txt */ #include <iostream> #include <cctype> #include &l ...
- Java_动态加载类(英文)
It is possible to load and reload classes at runtime in Java, though it is not as straightforward as ...
- Linq to EF 与Linq to Object 使用心得
大家都知道Linq既可以用来查询数据库对象(我这里指的是Entity FrameWork里的Model对象),也可以用来查询内存中的IEnumerable对象. 两者单独查询时都不会出现什么问题,不过 ...
- (译+注解)node.js的C++扩展入门
声明:本文主要翻译自node.js addons官方文档.部分解释为作者自己添加. 编程环境: 1. 操作系统 Mac OS X 10.9.51. node.js v4.4.22. npm v3.9. ...
- Node.js C/C++ 插件
插件 Addons 是动态链接的共享对象.他提供了 C/C++ 类库能力.这些API比较复杂,他包以下几个类库: V8 JavaScript, C++ 类库.用来和 JavaScript 交互,比如创 ...
- iOS命名规范(转载)
转载地址:http://www.cnblogs.com/qiqibo/archive/2012/09/05/2671553.html 正文: • 格式化代码 ◦ 指针“*”号的位置 ▪ 如:NSStr ...
- 值得借鉴的Objective-C编程规范
Daniel's Objective-C Coding Style Guidelines http://google-styleguide.googlecode.com/svn/trunk/objcg ...
随机推荐
- rest framework 序列化之depth遇到用户表外键的尴尬情况
rest framework 序列化之depth遇到用户表外键的尴尬情况 问题:ModelSerializer序列化使用depth=1直接扩表把用户表所有信息查询出来的情况 class xxxSeri ...
- Java - 判断字符串是否是回文
首先,回文是指类似于“12345”,“abcdcba”的形式,即正念和反念都是一样的字符串 判断字符串是否是回文,这边介绍3种办法 将字符串翻转,判断翻转后的字符串和原字符串是否相等 public s ...
- tmux的基本使用
tmux的基本使用 tmux 最近发现了一个linux终端非常好用的工具,可以快速分屏 使用方法 参考
- Abaqus 载荷分类(部分)
目录 1. 集中载荷 1.1 集中载荷施加方法 1.2 定义集中跟随力 1.3 指定文件定义集中节点力 2. 分布载荷 2.1 分布载荷分类 3. 热载荷 3.1 模拟热辐射 3.2 直接定义热流量 ...
- java.lang.OutOfMemoryError: GC overhead limit exceeded异常处理
今天写程序遇到个之前从没遇到的异常-----java.lang.OutOfMemoryError: GC overhead limit exceeded,下面附上解决方法 异常: 解决方法: 鼠标右击 ...
- java双亲委派模型
Java类加载器(ClassLoader) 双亲委派模式要求除了顶层的启动类加载器外,其余的类加载器都应当有自己的父类加载器,请注意双亲委派模式中的父子关系并非通常所说的类继承关系,而是采用组合关系来 ...
- 关于XMlHttpRequest对象
//创建XMLHttpRequest对象的三种方法 1 var xhr = createXMLHttpRequest(); function createXMLHttpRequest(){ try{ ...
- JAVA基础学习(4)之循环控制
4循环控制 4.1 for循环 4.1.1 for循环 固定次数for循环 先执行一次do-while循环 其他while循环 Scanner in = new Scanner(System.in); ...
- mysql int类型字段插入空字符串时自动转为0
mysql int类型字段插入空字符串时自动转为0 如果不想转的话可以修改配置文件 修改 my.ini 文件. # Set the SQL mode to strictsql-mode=”STRICT ...
- 让 typora和word一样好用
让 typora和word一样好用 :https://github.com/itcastWsy/typora_copy_images typora是一款支持实时预览的markdown编辑器,作者在使 ...