locked
Compilation Error - Make sure that the class defined in this code file matches the 'inherits' attribute RRS feed

  • Question

  • User-1394491597 posted

    Hi,

    Rookie question, hopefully there's an easy answer.

    I'm trying to test an ASP.NET function we have been provided with by a supplier but I'm falling at the first fence.

    The ASPX page (enctest.aspx) starts with...

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="enctest.aspx.vb" Inherits="enctest" %>

    ...and the code behind page (enctest.aspx.vb) starts with...

    Imports System
    Imports System.IO
    Imports System.Linq
    Imports System.Security.Cryptography
    Imports System.Text

    The rest of the code is irrelevant here because the error I get is...

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: 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).

    Source Error:
    Line 1: Imports System

    I tried changing the first line of the ASPX file to...

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="enctest.aspx.vb" Inherits="system" %>

    ...but still get the same error. The detailed compiler output is different for the 2 tries though. For Inherits="system" the errors are mostly like this...

    vbc : warning BC40057: Namespace or type specified in the project-level Imports 'System.Xml.Linq' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
    vbc : warning BC40057: Namespace or type specified in the project-level Imports 'System.Web.UI.HtmlControls' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
    vbc : warning BC40057: Namespace or type specified in the project-level Imports 'System.Web.UI.WebControls.WebParts' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
    

    ...and for Inherits="enctest" the errors are fewer but more varied, like...

    C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\cdeebc40\7377a1ce\App_Web_fq0maual.0.vb(43) : error BC30456: 'Context' is not a member of 'enctest'.
    Return CType(Me.Context.Profile,System.Web.Profile.DefaultProfile)
                             ~~~~~~~~~~                                           
    C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\cdeebc40\7377a1ce\App_Web_fq0maual.0.vb(49) : error BC30456: 'Context' is not a member of 'enctest'.
    Return CType(Me.Context.ApplicationInstance,System.Web.HttpApplication)
                             ~~~~~~~~~~                                                
    C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\cdeebc40\7377a1ce\App_Web_fq0maual.0.vb(59) : error BC30154: Class 'enctest_enctest_aspx' must implement 'ReadOnly Property IsReusable As Boolean' for interface 'System.Web.IHttpHandler'. Implementing property must have matching 'ReadOnly' or 'WriteOnly' specifiers.
    
    

    Can anyone point out where my (probably basic) error is here? Thank you

    Monday, May 11, 2020 10:46 AM

All replies

  • User-1330468790 posted

    Hi DPJ101,

     

    I can see that the problem should be located in "Inherits" attribute of the "<%@Page" directive as you guessed. 

    There are two things I need to confirm before providing you with the solution.

    1.  What you want to do is to test the function using a webforms page, right?
    2. Are you using Visual Studio to create the web application with the template?
    3. Could you please provide me with the version of the ASP.NET framework?

     

    If you are creating the web page from template, the "Inherits" attribute should be assigned with ProjectName.ClassName, which is as the same concept of the NameSpace.

    I suggest you change the structure for the Inherits attribute value.

     

    Another point is that I think what you want might be "CodeBehind" instead of "CodeFile" attribute.

    The difference between them (If you don't have interest of this, you could ignore below content).

    • A CodeBehind file is assumed to be compiled into an assembly that is deployed in the bin folder of your web site. When the ASP.NET engine loads your aspx file, it uses the Inherits directive to try to find that class. The CodeBehind file is primarily used to aid compiling (and tooling, e.g. "View Source") but the work is done at compile time.
    • A CodeFile file is located and compiled by ASP.NET at runtime, on demand. You can "pre-compile" your web site to fall back on the older model, which is useful if you won't want to deploy your source code to every web site. But by default, your CodeFile file is a .cs file that is deployed to the site, and the class is generated in the ASP.NET temporary storage folder. (From a technical perspective: CodeFile pages are partial class definitions, with only the custom code-behind part of the class actually deployed in the C# file; this is why CodeFile didn't exist initially, because the C# compiler could not initially do partial classes.)

    Above explanation comes from here.

     

    Solution:

    In short, the solution would be changing the "<%@Page" directive to:

    <%@ Page Language="VB" AutoEventWireup="false" CodeBehind="enctest.aspx.vb" Inherits="ProjectName.enctest" %>

      

    Hope this can help you.

    Best regards,

    Sean

    Tuesday, May 12, 2020 6:59 AM
  • User-1394491597 posted

    Hi Sean,

    When I made that change I got the following...

    Parser Error Message: Could not load type 'ProjectName.enctest'.

    Source Error:

    Line 1:  <%@ Page Language="VB" AutoEventWireup="false" CodeBehind="enctest.aspx.vb" Inherits="ProjectName.enctest" %>

    Yes, I'm trying to build some supplied code into a webform page eventually. I wasn't using Visual Studio initially, just trying to do the most basic test page to see if the script worked to start with but apparently this is failing before I even get to the actual meat of the script! When I set up a new web form in Visual Studio, it automatically sets the page declaration as <%@ Page Language="VB" AutoEventWireup="false" CodePage="enctest.aspx.vb" Inherits="enctest" %> so I had just copied and adapted that way from a different web form.

    I'm using VB not C#.

    Thanks

    Tuesday, May 12, 2020 9:20 AM