Unable to cast object of type 'System.Web.UI.Page' to type 'CareAlways.UserControls.PageBase'

I have a project that has custom controls developed under ASP.NET 1.1, and
I've successfully migrated to ASP.NET 2.0.  The format of the folder structure is as follows:
 /Core    /Business    /UserControls       MyTextBox.cs       PageBase.cs/WebApps   /MyWebApp  I have resolved all the problems to get the project to compile and run. My problem is that there are a few of my user controls that throw an error in the design mode of VS.NET 2005.  I get the following message: An exception of type 'System.InvalidCastException' occurred in CareAlways.UserControls.dll but was not handled in user code Additional information: Unable to cast object of type 'System.Web.UI.Page' to type 'CareAlways.UserControls.PageBase'. I have a PageBase that all of my webpages to usepublic class PageBase : System.Web.UI.Page      { On the webpage code-behind I have the followingpublic partial class AddProvider : CareAlways.UserControls.PageBase      {  public class MyTextBox : TextBox, IFieldSerializer      {            #region Designer properties….protected override void Render(HtmlTextWriter writer)            {                  base.Render(writer);            PageBase page = (PageBase)this.Page;     ç Errors out here My user control while running shows that ‘this’ is CareAlways.UserControls.MyTextBox 

There is no problem with all of this in VS2003 ASP 1.1 but after the conversion to VS2005 I get this. I have the latest SP1 on VS2005. Please let me know if you need any future information and what I can do to resolve this.

 

0
Randal7
8/3/2007 2:52:39 PM
asp.net.visual-studio-2005 7760 articles. 0 followers. Follow

7 Replies
905 Views

Similar Articles

[PageSpeed] 24

 I cleaned up my posting to make it easy to read. If anyone can help please let me know.

I have a project that has custom controls developed under ASP.NET 1.1, and I've successfully migrated to ASP.NET 2.0. 

 The format of the folder structure is as follows:

        /Core    

            /Business    

           /UserControls       

               MyTextBox.cs       

               PageBase.cs

     /WebApps

       /MyWebApp  

I have resolved all the problems to get the project to compile and run. My problem is that there are a few of my user controls that throw an error in the design mode of VS.NET 2005.  

I get the following message:  An exception of type 'System.InvalidCastException' occurred in CareAlways.UserControls.dll but was not handled in user code 

Additional information: Unable to cast object of type 'System.Web.UI.Page' to type 'CareAlways.UserControls.PageBase'. 

I have a PageBase that all of my webpages uses

public class PageBase : System.Web.UI.Page     

{

 On the webpage code-behind I have the following

public partial class AddProvider : CareAlways.UserControls.PageBase   

  

One of the user controls that don't work is below:

{  public class MyTextBox : TextBox, IFieldSerializer     

     {            #region Designer properties….

          protected override void Render(HtmlTextWriter writer)           

         {                 

              base.Render(writer);           

              PageBase page = (PageBase)this.Page;     ç Errors out here 

                                                            My user control while running shows that ‘this’ is CareAlways.UserControls.MyTextBox 

There is no problem with all of this in VS2003 ASP 1.1 but after the conversion to VS2005 I get this. I have the latest SP1 on VS2005.

Please let me know if you need any future information and what I can do to resolve this.

0
Randal7
8/6/2007 5:26:45 PM

1) MyTextBox Is not a user control, it's just a server control as it inherits from TextBox

2)  Could you please discover what value "this.Page.GetType()" returns in runtime?

 


Never ask users what they want, or they'll tell you
0
ArtemL
8/6/2007 5:39:03 PM

When I stop and watch  this.Page.GetType() I see the following:

-  this.Page.GetType() {Name = "Page" FullName = "System.Web.UI.Page"} System.Type {System.RuntimeType}

 Is this all you need me to send you?

0
Randal7
8/7/2007 12:27:41 PM

Then it looks like your page is not derived from your PageBase, it's derived from common System.Web.UI.Page.

Make sure you specified proper Inherits in aspx code


Never ask users what they want, or they'll tell you
0
ArtemL
8/7/2007 1:02:49 PM

 This is how my aspx page is coded. The textbox renders and works correctly when the web app is running

The problem is only when in designer when you bring up the web page that contains one of these text boxes.

public partial class AddProvider : CareAlways.Genesis.PageBase

{

       protected CareAlways.Genesis.CALabel CALabel_BranchID_display;       protected CareAlways.Genesis.CATextBox CATextBox_ProviderNumber;

      protected CareAlways.Genesis.CATextBox CATextBox_HiddenBranchID;

 

The source of the htm page is as follows:

<%@ Register TagPrefix="uc1" TagName="Header" Src="../Common/Header.ascx" %>

<%@ Register TagPrefix="cc1" Namespace="CareAlways.Genesis" Assembly="CareAlways.Genesis" %>

<%@ Register TagPrefix="uc1" TagName="Footer" Src="../Common/Footer.ascx" %>

<%@ Page language="c#" Codebehind="AddProvider.aspx.cs" AutoEventWireup="True" Inherits="Web.Agency.AddProvider" %>

 

<cc1:CATextBox id="CATextBox_1" runat="server" ></cc1:CATextBox>

 

I believe I have the proper inherits since stoping at the code below in Design mode and while running gives me these reults  

 PageBase page = (PageBase)this.Page;     ç Errors out here 

 

This is while running the web application

-  this.Page.GetType() {Name = "clients_clientpersonal_aspx" FullName = "ASP.clients_clientpersonal_aspx"} System.Type {System.RuntimeType}

 

This is while loading the page at design mode time

-  this.Page.GetType() {Name = "Page" FullName = "System.Web.UI.Page"} System.Type {System.RuntimeType}

 

My server control code is in a folder different that my web app

/Core    

          /Business    

          /Genesis <== Server Controls

               CATextBox .cs       

               CALabel .cs

 /WebApps

       /MyWebApp <== Web Application

 

 

0
Randal7
8/7/2007 1:29:51 PM

I am having the SAME problem as you. You explained it very well. I have yet to find a solution. Did you?

Please share it if you did. I have worried about this for quite a few days.

0
rkirby
8/13/2007 8:36:08 PM

I have not gotten any answers about my problem yet. I found the following link on this site:

http://forums.asp.net/t/957730.aspx

This sound like the same problem and the last thread of that one was dated 01-30-2006. I am hoping that someone has already found a solution or a work around this.

 Willing to try any advise that I can get for this problem.

0
Randal7
8/14/2007 7:56:04 PM
Reply:

Web resources about - Unable to cast object of type 'System.Web.UI.Page' to type 'CareAlways.UserControls.PageBase' - asp.net.visual-studio-2005

Resources last updated: 12/23/2015 8:23:27 PM