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?