Invalid Cast Exception Calling Bsse Class Method

  • Thread starter Thread starter Nick Flandry
  • Start date Start date
N

Nick Flandry

I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my
development environment (Win2K server running IIS 5) and a test environment (also Win2K server
running IIS 5), but fails on IIS 6 running on a Win2003 server.

The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide
some common functionality. The Page_Load handler the failing webpage starts out like this:

public class index : SitePage {

/* snip */

protected override void Page_Load(object sender, System.EventArgs e) {
base.Page_Load(sender, e);
...

SitePage is the custom-built class that derives from the Page class.

In other words, all I'm doing is trying to call a method in the base class to the Page.

Does anyone have any idea what might be causing this? Am I not allowed to call base methods in an
ASP.NET application?

- Nick
 
Hi Nick,


Thanks for posting in the community!
From your description, you encountered the "Invalid Cast Exception" in a
certain ASP.NET web page which derived from a custom parent page class.
Also, the exception occured when calling the parent page class's Page_Load
function, yes?
If there is anything I misunderstood, please feel free to let me know.

As for this problem, I'd like to confirm some further things on it:
1. As you mentioned the error page's Page_Load calls the base.Page_Load
then run into the error. Are you sure that it was at that point the Error
occurs or is there any thingelse suspicious in the error page's Page_Load
method? You can add a "try .... catch" block to establish this.

2. If the exception does occur when calling the "base.Page_Load" in the
derived page's Page_Load method, would you please try creating another
virutual method in the parent page and then override the method in the
derived page and also call "base.suchmethod" in it to see whether the same
problem occurs?

3. If the error doesn't occur in #2, I think the problem may due to
something with the certain "Page_Load" method. Is there any particular
operations in the parent page's Page_Load?

Please check out the above items. If you have any questions or got any new
findings, please feel free to let me know.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
As for this problem, I'd like to confirm some further things on it:
1. As you mentioned the error page's Page_Load calls the base.Page_Load
then run into the error. Are you sure that it was at that point the Error
occurs or is there any thingelse suspicious in the error page's Page_Load
method? You can add a "try .... catch" block to establish this.
I didn't use try/catch, but I did use multiple Response.Write()/Response.End() pairs to verify that
it was, in fact, precisely the line base.Page_Load() that caused the problem. I also used the
Response.Write()/Response.End() approach to show that execution never got "into" the base class; it
was the base.Page_Load() statement itself that blew up.
2. If the exception does occur when calling the "base.Page_Load" in the
derived page's Page_Load method, would you please try creating another
virutual method in the parent page and then override the method in the
derived page and also call "base.suchmethod" in it to see whether the same
problem occurs?

Good question. I'd done that, yes, and the same problem occurred.

- Nick
 
Hi Nick,

Thank you for the response. Regarding on the issue, I am
finding proper resource to assist you and we will update as soon as posible.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security(This posting is provided "AS IS",
with no warranties, and confers no rights.)
 
Hello all,

My name is Michael, and I will be working with the customer offline. I
will post the resolution to this site when we find out the problem and
resolution. Mark is currently working on something else so we will get to
this sometime next week.

Michael
 
Back
Top