【问题标题】:Compiled Class in Two Locations在两个位置编译的类
【发布时间】: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


【解决方案1】:

检查您的项目文件夹。您可能在解决方案中的某处引用了重复的程序集,这导致了冲突。您是否有引用相同程序集的父项目?

通读其中一些解决方案,看看是否有适合您的问题:

InvalidCastException for two Objects of the same type

ASP.NET unloading assemblies in the bin

Error Rendering control - [A] cannot be cast to [B] in the context LoadNeither

【讨论】:

  • 有趣的是,我正在使用一个具有 Serializable 属性的类。如果我将它存储在 HttpContext 的会话而不是页面 ViewState 中,页面似乎消失了。
猜你喜欢
  • 1970-01-01
  • 2013-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-28
  • 1970-01-01
  • 1970-01-01
  • 2021-10-22
相关资源
最近更新 更多