ASP.NET 2.0 编译错误:确保此代码文件中定义的类与“继承”匹配 属性
好吧,我完全陷入了这个编译错误。 它是一个网站(不是 Web 应用程序),.NET 2.0。
我在此目录中有一个文件:welcome_teams
文件名:default.aspx
页面声明:
<%@ Page Language="C#" MasterPageFile="~/masters/Site.master"
AutoEventWireup="true" CodeFile="default.aspx.cs"
Inherits="welcome_teams_default" %>`
代码隐藏
public partial class welcome_teams_default : System.Web.UI.Page
我不断收到此错误: 确保此代码文件中定义的类与“继承”属性匹配
我尝试删除该文件,然后将其再次添加为“新项目”,无论如何,错误仍然存在。
有任何想法吗?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
所以,它与命名空间无关,它与default2.aspx页面有关,指向default.aspx页面。
default2.aspx 页面的 CodeFile 属性被设置为“default.aspx.cs”,这把一切搞砸了。
对于将来可能遇到此问题的任何人,有时可以通过将 CodeFile 更改为 CodeBehind 来解决它。
另外,理论上这是一个名称空间问题,但天哪,我讨厌网站项目如何处理名称空间。
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.
最有可能的是,因为您的文件位于 Web 根目录内的文件夹中,所以当您创建它时,VS 会更改生成文件的命名空间。 例如,如果您的网站名称是 MyWebsite,那么它的默认命名空间就是 MyWebsite;
但对于您在welcome_teams内的aspx文件来说,它应该是:
所以在您的aspx页面中尝试更改
:
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;
but for your aspx file inside welcome_teams it should be:
so in your aspx page try changing:
to
您应该检查default.designer.cs 文件,并确保它也具有相同的类名。 有时,如果 Designer.cs 文件存在并且手动编辑(但有时出于其他原因),.aspx 页面和后面的代码之间的同步可能会被破坏。 要查看 .designer.cs 文件,您需要显示项目中的隐藏文件。
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.