两个地点的编译类

时间:2011-08-22 15:41:03

标签: .net asp.net vb.net compilation viewstate

我试图使用ASP.NET 4和VB.NET从ViewState加载List,这有点困难。当我尝试使用以下方法检索集合时:

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

调试显示该集合不为null并包含2个项目。该类仅定义一次,我已从C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files

清除了我的临时文件

一般情况下,我有时会在调试时进行快速更改时看到这个(我假设每个人都这样做),但是经过几次刷新之后。有什么我想念的吗?

1 个答案:

答案 0 :(得分:6)

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

阅读其中一些解决方案,看看是否有任何问题符合您的问题:

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