ASP.NET 2.0 Compilation Error: Verify that the class defined in this code file matches the inherits attribute

Ok, I am completely stuck with this compilation error. This is a website (not a web application), .NET 2.0.

I have a file in this directory: welcome_teams

file name: default.aspx

Page Ad:

<%@ Page Language="C#" MasterPageFile="~/masters/Site.master" AutoEventWireup="true" CodeFile="default.aspx.cs" Inherits="welcome_teams_default" %>` 

Code for

 public partial class welcome_teams_default : System.Web.UI.Page 

And I keep getting this error: Make sure the class defined in this code file matches the attribute 'inherits'

I tried to delete the file and add it again as a "new item", and no matter the error persists.

Any ideas?

Thanks!

+4
source share
3 answers

Thus, it had nothing to do with namespaces; it was linked to the default2.aspx page, pointing to the default.aspx page.

The default CodeFile attribute of 2.aspx was set to "default.aspx.cs", which screwed it all up.

For those who may encounter this problem in the future, you can sometimes solve it by changing the CodeFile to CodeBehind.

Also, theoretically this is a problem with namespace, but to god I hate how website designs handle namespaces.

+3
source

Most likely, since your file is located in a folder inside the web root, when it is created, VS changes the namespace for the generated files. For example, if your site name is MyWebsite , then the default namespace for it is MyWebsite;

 namespace MyWebsite 

but for your aspx file inside welcome_teams it should be:

 namespace MyWebsite.welcome_teams 

so on the aspx page try changing:

 <% Page ... inherits="welcome_teams_default" %> 

to

 <% Page .. Inherits="MyWebsite.welcome_teams.welcome_teams_default" %> 
+1
source

You should check the default.designer.cs file and make sure that it also has the same class name. Sometimes, if the designer.cs file exists and is edited manually (but sometimes for other reasons), the synchronization between the .aspx page and the code behind may become disturbed. To see the .designer.cs file, you will need to show hidden files in your project.

0
source

All Articles