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. 用python实现网络文件共享

    第一步:打开命令行 第二步:切换到要共享的文件夹目录 第三步:运行命令 python -m http.server 端口号 然后在浏览器输入显示的路径即可访问文件夹下的文件,点击即可下载,手机端亦可访 ...

  2. Bugku-CTF加密篇之进制转换(二进制、八进制、十进制、十六进制,你能分的清吗?)

    进制转换 二进制.八进制.十进制.十六进制,你能分的清吗?

  3. Codeforces Round #618 (Div. 1)B(几何,观察规律)

    观察猜测这个图形是中心对称图形是则YES,否则NO #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace ...

  4. 自己写了一个mysql连接的工具类【java】

    要用的话,包名自己可以改一下: package com.usa3v.dreamcenter.util; import java.sql.Connection; import java.sql.Driv ...

  5. 使用Python处理非对称加密-测试大佬常用的处理方式

    一.思考❓❔ 1.什么是非对称加密? 公钥加密系统,广泛用于数据加密传输 更详细的解释可参考维基百科( https://en.wikipedia.org/wiki/RSA_(cryptosystem) ...

  6. Cesium 基于MapBox底图加载3DTiles 模型

    3DTiles 模型采用   CATIA V5 R22 --->3dxml --->GLB--->B3DM var extent = Cesium.Rectangle.fromDeg ...

  7. 安卓基础(LiveData DataBinding)

    昨天因为有点事情,没有及时发表博客,昨天学习了LiveData和DataBinding,LiveData属于jetpack中的框架里面的,DataBinding可以进行数据绑定. 我分别利用这两部分知 ...

  8. 2016 Google code jam 大赛

    二,RoundC import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundE ...

  9. Android SDK Tools,Platform-tools,Build-tools分别有什么作用?

    SDK Tools:是下载sdk最基础的,由它再来下载Platform-tools,Build-tools platform-tools包含开发app的平台依赖的开发和调试工具,包括 adb.fast ...

  10. javaweb项目运转流程

    做web项目,不仅要会做,还需要了解其工作流程,为什么这么做!这些知道了.其他的都是渣渣.上图!对于web 项目了解他的运行流程之后,基本其他的都不是问题.web项目还是很简单的 这是简化的开发时常用 ...