两个地点的编译类

Ech*_*lon 5 .net vb.net asp.net viewstate compilation

我试图使用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
Run Code Online (Sandbox Code Playgroud)

我得到了例外:

[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'.
Run Code Online (Sandbox Code Playgroud)

调试显示该集合不为null并包含2个项目.该类只定义一次,我已经清理了我的临时文件C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files

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

Jam*_*son 6

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

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

两个相同类型的对象的InvalidCastException

ASP.NET中的ASP.NET卸载程序集

错误渲染控制 - [A]无法在上下文LoadNeither中强制转换为[B]