Designer.cs 文件自动创建错误
尽管我有缺陷,但我在以 Visual Studio 2008 向 .designer.cs 文件添加不正确的代码的形式创建错误时收到了一些不必要的帮助。 我很感激,这样做可能是因为我的疏忽或错误 - 但我会用我实际上是一个初出茅庐的 ASP.NET 开发人员为借口,所以我仍在学习。
解决方案导出器的相关部分如下所示:
/Prototypes
/Project01.Master
- Project01.Master.cs
- Project01.Master.designer.cs
/SampleApplication.aspx
- SampleApplication.aspx.cs
- SampleApplication.aspx.designer.cs
我不完全确定问题中应包含哪些文件,因此我将尽力猜测。 .Master.cs 和 SampleApplication.aspx.cs 都将自身包含在 Project01.Prototypes 命名空间中(尽管我对此并不重视,但它是自动添加并工作的,而我不需要考虑它) 。
SampleApplication.aspx 的顶部如下(以允许访问母版页理论上公开的某些属性。
<%@ Page Language="C#" MasterPageFile="~/Prototypes/Project01.Master" AutoEventWireup="true" CodeBehind="SampleApplication.aspx.cs" Inherits="Project01.Prototypes.SampleApplication" %>
<%@ MasterType VirtualPath="~/Prototypes/Project01.Master" %>
在 SampleApplication.aspx.designer.cs 中是:
namespace Project01.Prototypes {
public partial class SampleApplication {
public new Project01.Prototypes.Project01 Master {
get {
return ((Project01.Prototypes.Project01)(base.Master));
}
}
}
}
所有这些都会导致错误:
The type name 'Prototypes' does not exist in the type 'Project01.Prototypes.Project01'
我可以修复此错误并且通过删除类本身中的“Project01.Prototypes.”引用(保留命名空间)来再次进行构建我的问题是,这只是一个临时解决方案,因为 Visual Studio 不断将其添加回来 - 所以我猜想问题是我的错误实际位于哪里?
ps 如果这很重要,我正在使用 ASP.NET MVC Web 应用程序在 Visual Studio 2008 中运行。
Flawed as I am, I've received some unneeded help in creating errors in the form of Visual Studio 2008 adding incorrect code to a .designer.cs file. I appreciate, it is probably doing this because of my omission or error - but I will use the excuse that I am in actuality a fledgeling ASP.NET developer so I'm still learning.
The relevant parts of the solution exporer look like this:
/Prototypes
/Project01.Master
- Project01.Master.cs
- Project01.Master.designer.cs
/SampleApplication.aspx
- SampleApplication.aspx.cs
- SampleApplication.aspx.designer.cs
I'm not entirely sure which files to include in the question, so I'll try and guess as best I can. Both the .Master.cs and SampleApplication.aspx.cs include themselves within the Project01.Prototypes namespace (though I'm not precious about that, it's something that was auto-added and worked while I didn't need to think about it).
At the top of SampleApplication.aspx is the following (to enable access to some properties that the Master Page in theory, exposes.
<%@ Page Language="C#" MasterPageFile="~/Prototypes/Project01.Master" AutoEventWireup="true" CodeBehind="SampleApplication.aspx.cs" Inherits="Project01.Prototypes.SampleApplication" %>
<%@ MasterType VirtualPath="~/Prototypes/Project01.Master" %>
Within the SampleApplication.aspx.designer.cs is:
namespace Project01.Prototypes {
public partial class SampleApplication {
public new Project01.Prototypes.Project01 Master {
get {
return ((Project01.Prototypes.Project01)(base.Master));
}
}
}
}
All this results in the error:
The type name 'Prototypes' does not exist in the type 'Project01.Prototypes.Project01'
I can fix this error and get the build going again by getting rid of the 'Project01.Prototypes.' references within the class itself (leaving the namespace). My problem is that this is only a temporary solution as Visual Studio keeps adding it back in - so I guess the question is where is my mistake actually located?
p.s. If it's important, I'm running in Visual Studio 2008 with a ASP.NET MVC Web Application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是您的顶级命名空间和母版页类具有相同的名称。 因此,当编译器尝试解析类型时,它会在母版页类中查找类型“Prototypes.Project01”。
我建议在 mastertype 指令上使用 typename 属性而不是 virtualpath,但是当您在那里使用限定的类型名称时,解析器似乎会阻塞。 因此,在我看来,您有两种选择:
The problem is that your top-level namespace and your master page class have the same name. So when the compiler tries to resolve the type, it's looking for a type "Prototypes.Project01" inside your master page class.
I would recommend using the typename property on the mastertype directive instead of virtualpath, but the parser seems to choke when you use a qualified type name there. So as I see it you have two alternatives:
您是否尝试过关闭 VS 2008,然后再次打开您的项目?
这通常对我来说是这样的。
Have you tried closing down VS 2008, and then opening your project again?
That normally does it for me.