R
Roshawn
Hi,
I have a generic list of objects which I place in the cache. When trying to retrieve the
data in the cache and place it in another object of the same type, I get an
InvalidCastException. Here's my code:
'global variable
Dim fItems as List (Of Item)'Item is a custom object
'inside the Page_Load event
'other code omitted
If Not Cache("Items") Is Nothing Then
fItems = DirectCast(Cache("FormItems"), List(Of Item)) 'error happens here
Else 'data isn't cached
Dim ees = From itm In xdoc.Descendants(nsp + "item") Select New Item With {.Text = _
(e-mail address removed), .Value = (e-mail address removed), .ParentName =
(e-mail address removed)}
Cache.Insert("Items", ees.ToList)
fItems = ees.ToList
End If
Now, when I first run the code, everything goes as expected. But when I try to access the
cached data, I get this error:
"Unable to cast object of type 'System.Collections.Generic.List`1[_Default+Item]' to type
'System.Collections.Generic.List`1[_Default+Item]'"
Instead of using DirectCast I've even tried using CType but still I get the same problem.
Could somebody help me? I have no idea what I'm doing wrong.
I have a generic list of objects which I place in the cache. When trying to retrieve the
data in the cache and place it in another object of the same type, I get an
InvalidCastException. Here's my code:
'global variable
Dim fItems as List (Of Item)'Item is a custom object
'inside the Page_Load event
'other code omitted
If Not Cache("Items") Is Nothing Then
fItems = DirectCast(Cache("FormItems"), List(Of Item)) 'error happens here
Else 'data isn't cached
Dim ees = From itm In xdoc.Descendants(nsp + "item") Select New Item With {.Text = _
(e-mail address removed), .Value = (e-mail address removed), .ParentName =
(e-mail address removed)}
Cache.Insert("Items", ees.ToList)
fItems = ees.ToList
End If
Now, when I first run the code, everything goes as expected. But when I try to access the
cached data, I get this error:
"Unable to cast object of type 'System.Collections.Generic.List`1[_Default+Item]' to type
'System.Collections.Generic.List`1[_Default+Item]'"
Instead of using DirectCast I've even tried using CType but still I get the same problem.
Could somebody help me? I have no idea what I'm doing wrong.