|
 |
aspdotnet_website_programming thread: Re: System.InvalidCastException: Specified cast is not valid.
Message #1 by "Jay Semel" <ysemel@h...> on Sun, 1 Dec 2002 17:04:16
|
|
I am having the same problem - Using C#
I really wanted to use the authentication model built in with .net but it
seems it just doesn't work properly for me. Oh well - I can still use it
in the cache (or session)
If anyone knows anything more on the subject please let us know
Thanks
Message #2 by "Charles Walsek" <cwalsek@w...> on Sun, 1 Dec 2002 18:03:14 -0500
|
|
Jay,
Are you using VS.NET? Check the OnInit() generated function. The Principal
object is created in the PageBase, so if you make sure you call the
baseOnInit first, the object will exist when you attempt the cast in the
page.
Seems that VS.NET generates the code in the opposite order required. If you
reverse the order, you should be OK. There has been some discussion on this
previously. I may not have the spelling right on these functions. All my
code is on another box so I can't check it out further.
--Chas
----- Original Message -----
From: "Jay Semel" <ysemel@h...>
To: "Website Programming with ASP.NET"
<aspdotnet_website_programming@p...>
Sent: Sunday, December 01, 2002 5:04 PM
Subject: [aspdotnet_website_programming] Re: System.InvalidCastException:
Specified cast is not valid.
> I am having the same problem - Using C#
>
> I really wanted to use the authentication model built in with .net but it
> seems it just doesn't work properly for me. Oh well - I can still use it
> in the cache (or session)
>
> If anyone knows anything more on the subject please let us know
>
> Thanks
> ---
> Professional Design Patterns in VB.NET:
> Building Adaptable Applications
>
> Want to know how design patterns bring reusable
> design and adaptabilty to your applications? How
> to recognize the need for a design pattern
> solution? How to select, design, and implement
> the right patterns? How parts of the .NET Framework
> (like the .NET Data Providers and .NET Remoting)
> take advantage of design patterns? This book
> presents a practical approach to using design
> patterns in VB.NET, by focusing on the relevance
> of design patterns in the different tiers of a
> distributed n-tier architecture.
>
> http://www.wrox.com/books/1861006985.htm
>
Message #3 by "Jay Semel" <ysemel@h...> on Tue, 3 Dec 2002 20:37:26
|
|
Thanks for getting back to me Chas,
I have yet to get the chance to try your recommendation - I hope to soon.
Truthfully, I dont understand how this will work - I'm only using the
PhilePrincipal class inside a class that's inherited from PhileBase -
Shouldn't the Load method of PhileBase be executed before any code from
the inherited class is executed?? From the results it's obviously not but
why??? If someone can point me in the right direction here it would be
greatly appreciated
Thanks
> Jay,
Are you using VS.NET? Check the OnInit() generated function. The
Principal
object is created in the PageBase, so if you make sure you call the
baseOnInit first, the object will exist when you attempt the cast in the
page.
Seems that VS.NET generates the code in the opposite order required. If
you
reverse the order, you should be OK. There has been some discussion on
this
previously. I may not have the spelling right on these functions. All my
code is on another box so I can't check it out further.
--Chas
----- Original Message -----
From: "Jay Semel" <ysemel@h...>
To: "Website Programming with ASP.NET"
<aspdotnet_website_programming@p...>
Sent: Sunday, December 01, 2002 5:04 PM
Subject: [aspdotnet_website_programming] Re: System.InvalidCastException:
Specified cast is not valid.
> I am having the same problem - Using C#
>
> I really wanted to use the authentication model built in with .net but it
> seems it just doesn't work properly for me. Oh well - I can still use it
> in the cache (or session)
>
> If anyone knows anything more on the subject please let us know
>
> Thanks
> ---
> Professional Design Patterns in VB.NET:
> Building Adaptable Applications
>
> Want to know how design patterns bring reusable
> design and adaptabilty to your applications? How
> to recognize the need for a design pattern
> solution? How to select, design, and implement
> the right patterns? How parts of the .NET Framework
> (like the .NET Data Providers and .NET Remoting)
> take advantage of design patterns? This book
> presents a practical approach to using design
> patterns in VB.NET, by focusing on the relevance
> of design patterns in the different tiers of a
> distributed n-tier architecture.
>
> http://www.wrox.com/books/1861006985.htm
>
Message #4 by "Charles Walsek" <cwalsek@w...> on Wed, 4 Dec 2002 06:10:13 -0500
|
|
You would think the base class code would load first, but I don't think it's
the case. When I first encountered the InvalidCastException, I was confused
too. I ended up writing a global event handler (global.asax) that created
the SitePrincipal object. Global handlers are always guarenteed to execute
first. That worked for me & I thought it was a done deal.
Later on I stumbled on reversing the order I mentioned below. That did the
trick, and I was able to retire the global event handler code. When you get
a chance, try it out.
BTW: I have not checked, but I think the wrox code download executes the
functions in the order I mentioned. Maybe we have just been conditioned to
think that VS.NET generated code must be OK. But it is a release 1.0
product.....
----- Original Message -----
From: "Jay Semel" <ysemel@h...>
To: "Website Programming with ASP.NET"
<aspdotnet_website_programming@p...>
Sent: Tuesday, December 03, 2002 8:37 PM
Subject: [aspdotnet_website_programming] Re: System.InvalidCastException:
Specified cast is not valid.
> Thanks for getting back to me Chas,
>
> I have yet to get the chance to try your recommendation - I hope to soon.
>
> Truthfully, I dont understand how this will work - I'm only using the
> PhilePrincipal class inside a class that's inherited from PhileBase -
> Shouldn't the Load method of PhileBase be executed before any code from
> the inherited class is executed?? From the results it's obviously not but
> why??? If someone can point me in the right direction here it would be
> greatly appreciated
>
> Thanks
>
>
>
> > Jay,
>
> Are you using VS.NET? Check the OnInit() generated function. The
> Principal
> object is created in the PageBase, so if you make sure you call the
> baseOnInit first, the object will exist when you attempt the cast in the
> page.
>
> Seems that VS.NET generates the code in the opposite order required. If
> you
> reverse the order, you should be OK. There has been some discussion on
> this
> previously. I may not have the spelling right on these functions. All my
> code is on another box so I can't check it out further.
>
> --Chas
>
>
> ----- Original Message -----
> From: "Jay Semel" <ysemel@h...>
> To: "Website Programming with ASP.NET"
> <aspdotnet_website_programming@p...>
> Sent: Sunday, December 01, 2002 5:04 PM
> Subject: [aspdotnet_website_programming] Re: System.InvalidCastException:
> Specified cast is not valid.
>
>
> > I am having the same problem - Using C#
> >
> > I really wanted to use the authentication model built in with .net but
it
> > seems it just doesn't work properly for me. Oh well - I can still use it
> > in the cache (or session)
> >
> > If anyone knows anything more on the subject please let us know
> >
> > Thanks
> > ---
> > Professional Design Patterns in VB.NET:
> > Building Adaptable Applications
> >
> > Want to know how design patterns bring reusable
> > design and adaptabilty to your applications? How
> > to recognize the need for a design pattern
> > solution? How to select, design, and implement
> > the right patterns? How parts of the .NET Framework
> > (like the .NET Data Providers and .NET Remoting)
> > take advantage of design patterns? This book
> > presents a practical approach to using design
> > patterns in VB.NET, by focusing on the relevance
> > of design patterns in the different tiers of a
> > distributed n-tier architecture.
> >
> > http://www.wrox.com/books/1861006985.htm
> >
>
> ---
> Professional Design Patterns in VB.NET:
> Building Adaptable Applications
>
> Want to know how design patterns bring reusable
> design and adaptabilty to your applications? How
> to recognize the need for a design pattern
> solution? How to select, design, and implement
> the right patterns? How parts of the .NET Framework
> (like the .NET Data Providers and .NET Remoting)
> take advantage of design patterns? This book
> presents a practical approach to using design
> patterns in VB.NET, by focusing on the relevance
> of design patterns in the different tiers of a
> distributed n-tier architecture.
>
> http://www.wrox.com/books/1861006985.htm
>
|
|
 |