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]的更多相关文章

  1. 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 ...

  2. WinPhone学习笔记(四)——磁贴

    对每个Windows Phone的使用者来说,给他们的第一印象就是大大小小的磁贴——Metro,本篇介绍的是Windows Phone的磁贴,提到的有开始菜单的磁贴,也有在App里面的磁贴. 开始菜单 ...

  3. 词频统计_输入到文件_update

    /* 输入文件见337.in.txt 输出文件见338.out.txt */ #include <iostream> #include <cctype> #include &l ...

  4. Java_动态加载类(英文)

    It is possible to load and reload classes at runtime in Java, though it is not as straightforward as ...

  5. Linq to EF 与Linq to Object 使用心得

    大家都知道Linq既可以用来查询数据库对象(我这里指的是Entity FrameWork里的Model对象),也可以用来查询内存中的IEnumerable对象. 两者单独查询时都不会出现什么问题,不过 ...

  6. (译+注解)node.js的C++扩展入门

    声明:本文主要翻译自node.js addons官方文档.部分解释为作者自己添加. 编程环境: 1. 操作系统 Mac OS X 10.9.51. node.js v4.4.22. npm v3.9. ...

  7. Node.js C/C++ 插件

    插件 Addons 是动态链接的共享对象.他提供了 C/C++ 类库能力.这些API比较复杂,他包以下几个类库: V8 JavaScript, C++ 类库.用来和 JavaScript 交互,比如创 ...

  8. iOS命名规范(转载)

    转载地址:http://www.cnblogs.com/qiqibo/archive/2012/09/05/2671553.html 正文: • 格式化代码 ◦ 指针“*”号的位置 ▪ 如:NSStr ...

  9. 值得借鉴的Objective-C编程规范

    Daniel's Objective-C Coding Style Guidelines http://google-styleguide.googlecode.com/svn/trunk/objcg ...

随机推荐

  1. Unity2018破解版安装教程(windows)

    最近啊,在研究一些游戏的搭建与算法的创新,所以学习使用unity,下面来跟大家分享Unity2018的安装过程. 1.下载安装包(我的下载地址:链接:https://pan.baidu.com/s/1 ...

  2. 一篇文章了解JsBridge

    链接:https://blog.csdn.net/duwen90/article/details/79389545

  3. swiper移动端全屏播放动态获取数据

    html:  <link rel="stylesheet" href="css/swiper.min.css">   <div class=& ...

  4. 基于XML装配bean的解析-Bean的作用域

    一.Bean的种类1.普通bean:<bean  id=""  class="A"> ,spring直接创建A实例,并返回. 2.FactoryBe ...

  5. 升级 .net core3.1

    下载sdk3.1版本 升级包 然后build之后看提示若有其他包版本太低则按照提示将其他包升级 build --> run 报错,修复bug(主要由于包更新之后有些方法或者属性被移除造成无法使用 ...

  6. Educational Codeforces Round 78 (Rated for Div. 2)E(构造,DFS)

    DFS,把和当前结点相连的点全都括在当前结点左右区间里,它们的左端点依次++,然后对这些结点进行DFS,优先对左端点更大的进行DFS,这样它右端点会先括起来,和它同层的结点(后DFS的那些)的区间会把 ...

  7. [原]eclipse中spring配置文件的自动提示和命名空间的添加

    在用spring或者springmvc框架进行开发时,编辑applicationcontext.xml等配置文件是必不可少的,在eclipse中打开applicationcontext.xml通常是这 ...

  8. 连接mongodb服务

    语法:mongo.exe ip地址:端口号/数据库名(默认连接test) mongodb的默认端口号:27017 MongoDB内部结构   MongoDB MySQL 文档(Document) 记录 ...

  9. [JavaScript] 两个数相除有余数时结果加1

    实现代码 ; ; ?(total/item):(Math.floor(total/item)+); console.log(page)

  10. Linux动态库路径配置

    参考链接:https://blog.csdn.net/blade2001/article/details/32839937 为什么要关注动态库路径配置,是因为工作中遇到动态库依赖其他动态库,而其他动态 ...