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

StackOverflow https://stackoverflow.com/questions/1088204

Question

Okay I'm completely stuck on this compilation error. It's a Web Site (not web app), .NET 2.0.

I have a file in this directory: welcome_teams

file name: default.aspx

Page Declaration:

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

Code Behind

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

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

I've tried deleting the file, and adding it again as "new item" and no matter what, the error persists.

Any ideas?

Thanks!

Was it helpful?

Solution

So, it had nothing to do with namespaces, it has to do with the default2.aspx page, pointing to the default.aspx page.

The default2.aspx page's CodeFile attribute was set to "default.aspx.cs" which screwed it all up.

For anyone who might have this problem in the future though, you can sometimes solve it by changing CodeFile to CodeBehind.

Also, in theory it was a namespace issue, but god do I hate how Website projects handle namespaces.

OTHER TIPS

Most probably as your file is in a folder inside web root, when you create it VS changes namespace for generated files. Like, if your site name is MyWebsite then default namespace for it is MyWebsite;

namespace MyWebsite

but for your aspx file inside welcome_teams it should be:

namespace MyWebsite.welcome_teams

so in your aspx page try changing:

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

to

<% Page .. Inherits="MyWebsite.welcome_teams.welcome_teams_default" %>

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top