Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiled Class in Two Locations

I'm a tad stuck trying to get a List to load from the ViewState using ASP.NET 4 and VB.NET. When I try to retrieve a collection using:

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

I get the exception:

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

Debugging shows that the collection is not null and contains 2 items. The class is only defined once and I've cleaned my temporary files from C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files

Generally I sometimes see this (I assume everyone does) when making rapid changes while debugging, but it goes after a couple of refreshes. Is there something I'm missing?

like image 485
Echilon Avatar asked Aug 22 '11 15:08

Echilon


1 Answers

Check your project folders. You probably have a duplicate assembly referenced somewhere in the solution, which is causing a conflict. Do you have a parent project that references the same assembly?

Read through a few of these solutions to see if anything fits your problem:

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

like image 137
James Johnson Avatar answered Sep 30 '22 09:09

James Johnson