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. Tomcat目录说明

    apache-tomcat-x.x.xx bin:保存启动与监控Tomcat的命令文件的文件夹 conf:保存Tomcat配置文件的文件夹,如servlet.xml为服务器的主配置文件,web.xml ...

  2. appium---如何判断原生页面和H5页面

    目前app中存在越来越多的H5页面了,对于一些做app自动化的测试来说,要求也越来越高,自动化不仅仅要支持原生页面,也要可以H5中进行操作自动化,这一篇介绍如何查看页面上是否存在H5页面,这里首先要了 ...

  3. angular2项目打包部署的坑

    1.ng项目打包后,打开index.html,发现页面是空白的,F12查看,发现js和css引入的路径不对 这里要将package.json文件的打包命令改成 ng build --prod --ba ...

  4. opencv编译静态库时选择MD模式无效的原因

    在Cmake-gui上看到的明明是MD运行库依赖,生成MS项目时却变成了MT运行库依赖. 原因在于编译静态库时内部做了自动替换.

  5. js获取用户当前地理位置(省、市、经纬度)

    在很多情况下,我们需要用到定位功能,来获取用户当前位置.当前比较流行的定位API有腾讯地图.百度地图.高德地图.搜狗地图等等,在这里我使用的是腾讯地图定位API,根据用户IP获取用户当前位置,API返 ...

  6. Git - 05. git log & git show

    1. 概述 有了提交, 就必须有日志 日志用处很多, 这里我就不多说了 2. 项目日志 概述 查看当前分支的 提交记录 命令 普通查看 命令 > git log 显示 commit id 包括 ...

  7. Python 之路

    Python之路[第一篇]:Python简介和入门 Python之路[第二篇]:Python基础(一) Python之路[第三篇]:Python基础(二) Python之路[第四篇]:模块 Pytho ...

  8. php的str_pad()函数

    实例 填充字符串的右侧,到30个字符的新长度 <?php $str = "Hello World"; echo str_pad($str,30,"."); ...

  9. java 并交集运算

    在面试的过程中,忘记了List中还可以进行交并集运算,这也是常见的数据问题啊,这也是常见的数据结构问题---集合,面试的过程中一直没有想到这种数据结构 java中API中已经集成了并交集的运算. 代码 ...

  10. 基于maven+java+TestNG+httpclient+poi+jsonpath+ExtentReport的接口自动化测试框架

    接口自动化框架 项目说明 本框架是一套基于maven+java+TestNG+httpclient+poi+jsonpath+ExtentReport而设计的数据驱动接口自动化测试框架,TestNG ...