Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl)

Last post 09-16-2009 4:31 PM by Das2. 7 replies.

Sort Posts:

  • Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl)

    11-29-2005, 1:23 PM
    • Member
      5 point Member
    • brian.wenhold
    • Member since 11-29-2005, 4:53 PM
    • Orlando, Florida
    • Posts 1

    Here is the page directive for the page that throws the error:

    <%
    @ Page language="c#" Inherits="University.AspNet.Index" CodeFile="Index.aspx.cs" %>

    The code behind file Index.aspx.cs starts like this:

    using University.Framework.UI;

    namespace University.AspNet

    {
          
    public partial class Index : University.Framework.UI.HomePage

    The code behind is extending this HomePage class, which is in turn an extenstion of another class University.Framework.UI.Page, which extends the System.Web.UI.Page class.

    Am I misusing the Inherits parameter somehow?

    Oddly there is a blue squiggle under only the first 'i' in University in the code behind that links to the error in the subject of this post.

    Any insights as to the nature of this error would be greatly appreciated. Thanks.

  • Re: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl)

    11-30-2005, 12:56 PM
    Answer
    • Member
      345 point Member
    • NHuffman
    • Member since 11-07-2005, 5:47 PM
    • Posts 67
    • AspNetTeam
    It looks like you are missing the CodeFileBaseClass attribute, which should point to your baseclass.

    <%@ Page language="c#" Inherits="University.AspNet.Index" CodeFile="Index.aspx.cs" CodeFileBaseClass="XXXXXX" %>

    CodeFileBaseClass

    Specifies a path to a base class for a page and its associated code-behind class. This attribute is optional, but when it is used the CodeFile attribute must also be present. Use this attribute when you want to implement a shared scenario, where you define common fields (and optionally, associated events) in a base class to reference the controls declared in a Web page. Because of the ASP.NET code generation model, if you defined the fields in a base class without using the this attribute, at compile time new member definitions would be generated for the controls declared in the Web page (within a separate partial class stub), and your desired scenario would not work. But if you use the CodeFileBaseClass attribute to associate the base class with the page, and you make your partial class (its name is assigned to the Inherits attribute and its source file is referenced by the CodeFile attribute) inherit from the base class, then the fields in the base class will be able to reference the controls on the page after code generation.

    This posting is provided "AS IS" with no warranties, and confers no rights.

    - Neil -
  • Re: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl)

    03-03-2007, 8:54 PM
    • Member
      6 point Member
    • demonite
    • Member since 03-04-2007, 1:52 AM
    • Posts 3
    Actually I had this error and it occurred because I tried adding the class to a "namespace", try removing the name space.
  • Re: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl)

    11-07-2007, 9:44 AM
    • Member
      34 point Member
    • nirniron
    • Member since 11-07-2007, 2:43 PM
    • Israel
    • Posts 98

    thanks.. it works

    Nir

    If i helped you please mark as answered..
  • Re: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl)

    11-27-2008, 10:42 AM
    • Member
      14 point Member
    • larry302
    • Member since 11-27-2008, 3:36 PM
    • Posts 15

    Changing the attribute from "codefile" to "codebehind", should do the trick.

     I found the related article here. http://tek-wise.blogspot.com/2009/07/aspnet-make-sure-that-class-defined-in.html

    Larry Bargers
    VB.net Software Developer
  • Re: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl)

    05-06-2009, 2:34 AM
    • Member
      8 point Member
    • arviman
    • Member since 04-06-2008, 7:06 AM
    • Los Angeles, CA
    • Posts 4

    There is no need to remove the namespace. In your <%page %> tag, change the Inherits attribute to point to the full class name instead of just the class name.

    That is, if a code-behind class "_Default" is in the namespace MyNameSpace, then change Inherits = "MyNameSpace._Default" from Inherits = "_Default"

  • Re: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl)

    05-27-2009, 11:41 AM
    • Member
      14 point Member
    • psusme1
    • Member since 03-24-2009, 3:46 PM
    • Posts 2

    I forgot to inherit System.Web.UI.Page in the basepage class....

     

    I put BasePage.cs in the App_Code folder which contains the implemented class BasePage.  I then inherited the BasePage class in MyClass like this:

     public partial class MyClass : BasePage { //define class}

     

    and then in the BasePage.cs make sure the class BasePage inherits from the System.Web.UI.Page class here.. if not.. make sure you add it like this...

    public class BasePage : System.Web.UI.Page{ //define basepage class here}

     

  • Re: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl)

    09-16-2009, 4:31 PM
    • Member
      2 point Member
    • Das2
    • Member since 07-16-2009, 6:37 PM
    • Posts 20
    1. Namespace X
          Namespace Y
            Namespace Z            
                Public Class BasePage
                    Inherits System.Web.UI.Page
     
     2. Public Class MainPageClass 
        Inherits X.Y.Z.BasePage
     
    3. <%@ Page AutoEventWireup="false" CodeFile="myPage.aspx.vb" Inherits="myPage" %>
        Code-behind:
              Partial Public Class myPage
                  Inherits MainPageClass 
     ----------------------------------------
    It's working fine locally in VWD-2008 but it's throwing an exception when I run the same app in WSS(sharepoint).
    Exception: error ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, 
    and that it extends the correct base class (e.g. Page or UserControl).   at System.Web.Compilation.AssemblyBuilder.Compile() 
     
    Any idea, where I am doing wrong! 
    Thanks

     

    DTS
Page 1 of 1 (8 items)