Thank you for your hint Scott. I tried it and it drives me even more crazy,
since in the debugger it works, but the same line "at runtime" fails.
I put a breakpoint before the line, and inspected the Session variable:
?System.Web.HttpContext.Current.Session["BackEnd"]
{BackEnd}
System.Object: {BackEnd}
con: {com.Transoft.TCA.TCAConnection}
looks okay, so I went ahead and assigned it to my private field, casting the
session variable:
this.backend = (BackEnd)System.Web.HttpContext.Current.Session["BackEnd"]
{BackEnd}
System.Object: {BackEnd}
con: {com.Transoft.TCA.TCAConnection}
and it works as well !!!
But now comes the thing I don't understand: if I step to the next statement,
which is exactly what I entered in the debugger window, it fails with the
Specified cast is not valid
message.
"Scott Allen" wrote:
[color=blue]
> Hi Carlo:
>
> Something must be in the session object you don't expect. Try to run
> the application in the debugger and put a breakpoint on the line
> causing the problem. Investigate what really exists in
> Session["BackEnd"].
>
> --
> Scott
>
http://www.OdeToCode.com
>
>
> On Tue, 17 Aug 2004 13:21:02 -0700, "Carlo Marchesoni"
> <CarloMarchesoni@discussions.microsoft.com> wrote:
>[color=green]
> >and I forgot to paste the error message:
> >
> >Specified cast is not valid.
> >Description: An unhandled exception occurred during the execution of the
> >current web request. Please review the stack trace for more information about
> >the error and where it originated in the code.
> >
> >Exception Details: System.InvalidCastException: Specified cast is not valid.
> >
> >
> >"Carlo Marchesoni" wrote:
> >[color=darkred]
> >> I have an ASP.NET/C# solution, where I can perfectly cast something I stored
> >> in the session object to a class of mine (BackEnd), as this:
> >> ->be = (BackEnd)Session["BackEnd"];<-
> >>
> >> But if I try to do the same:
> >> ->this.backend = (BackEnd)System.Web.HttpContext.Current.Session["BackEnd"]<--
> >> in another project of the same solution I got:
> >> public CustomerAccess(BackEnd backend, string culture) {
> >> this.backend = (BackEnd)System.Web.HttpContext.Current.Session["BackEnd"];
> >> ...
> >> at runtime. I can access the Session-state perfectly (because of a hint of
> >> Marcelo in this Newsgroup, so I referenced System.Web and everything looked
> >> okay) and cast for example to (string) without any problem.
> >> What could be the problem here ?
> >>[/color][/color]
>
>[/color]