I use a Session variable to store a custom object (all properties contain
strings) between postbacks. On occasion, mostly when I change and save code,
when I refresh the web page to see the changes, I get an error:
"System.Invalid CastException was unhandled by user code -Unable to cast
object of type 'QueryParameter s' to type 'QueryParameter s'"
in the function below which is called during Page_Load (_queryParamete rs =
QueryParameters .getInstance())
Public Shared Function getInstance() As QueryParameters
Dim instance As QueryParameters
If IsNothing(Curre nt.Session(SESS ION_VARIABLE)) Then
instance = New QueryParameters ()
instance.saveQP ToSession()
Else
instance = Current.Session (SESSION_VARIAB LE)
End If
Return instance
End Function
When I debug, a valid Session variable exists because the code goes to the
Else statement, and in the Watch window, I can see all the properties of the
custom object in the Session variable. Since 'instance' is typed as
QueryParameters and a Session variable exists that holds the object, I don't
understand why there is an error since these both seem to be typed correctly
as QueryParameters . Even when I explicitly type the session variable
(CType(Current. Session(SESSION _VARIABLE), QueryParameters )) the same error
appears.
If I close the browser completely, everything works, but I hate to have to
close a browser with every iteration of code changes.
Does anyone know why this error appears? Thanks for any help.
strings) between postbacks. On occasion, mostly when I change and save code,
when I refresh the web page to see the changes, I get an error:
"System.Invalid CastException was unhandled by user code -Unable to cast
object of type 'QueryParameter s' to type 'QueryParameter s'"
in the function below which is called during Page_Load (_queryParamete rs =
QueryParameters .getInstance())
Public Shared Function getInstance() As QueryParameters
Dim instance As QueryParameters
If IsNothing(Curre nt.Session(SESS ION_VARIABLE)) Then
instance = New QueryParameters ()
instance.saveQP ToSession()
Else
instance = Current.Session (SESSION_VARIAB LE)
End If
Return instance
End Function
When I debug, a valid Session variable exists because the code goes to the
Else statement, and in the Watch window, I can see all the properties of the
custom object in the Session variable. Since 'instance' is typed as
QueryParameters and a Session variable exists that holds the object, I don't
understand why there is an error since these both seem to be typed correctly
as QueryParameters . Even when I explicitly type the session variable
(CType(Current. Session(SESSION _VARIABLE), QueryParameters )) the same error
appears.
If I close the browser completely, everything works, but I hate to have to
close a browser with every iteration of code changes.
Does anyone know why this error appears? Thanks for any help.
Comment