【发布时间】:2011-08-22 15:41:02
【问题描述】:
我在尝试使用 ASP.NET 4 和 VB.NET 从 ViewState 加载列表时有点卡住了。当我尝试使用以下方法检索集合时:
Public Property ItemsForImport As List(Of ImportItem)
Get
Return IIf(ViewState("ItemsForImport") Is Nothing, New List(Of ImportItem), CType(ViewState("ItemsForImport"), List(Of ImportItem)))
End Get
Set(value As List(Of ImportItem))
ViewState("ItemsForImport") = value
End Set
End Property
我得到了例外:
[A]System.Collections.Generic.List`1[ImportItem] cannot be cast to [B]System.Collections.Generic.List`1[ImportItem].
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_32\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_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'.
调试显示该集合不为空且包含 2 个项目。这个类只定义了一次,我已经从C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files清除了我的临时文件
通常,在调试时进行快速更改时,我有时会看到这一点(我假设每个人都会看到),但它会在几次刷新后出现。我有什么遗漏吗?
【问题讨论】:
-
你试过用 DirectCast 代替 CType 吗?
标签: .net asp.net vb.net compilation viewstate