我在我的ASP.NET web应用程序中创建了一个单独的文件夹和页面。当我构建解决方案时,收到错误消息
The Namespace MyApp already contains a defintion for VDS下面是VDS.Master.cs的内容:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MayApp{
public partial class VDS : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}下面是VDS.Master.designer.cs的内容:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace MyApp.VDS {
public partial class VDS {
/// <summary>
/// Head1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlHead Head1;
/// <summary>
/// head control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.ContentPlaceHolder head;
/// <summary>
/// form1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlForm form1;
/// <summary>
/// ScriptManager1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.ScriptManager ScriptManager1;
/// <summary>
/// NavMenu control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Menu NavMenu;
/// <summary>
/// smds1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.SiteMapDataSource smds1;
/// <summary>
/// MainContent control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.ContentPlaceHolder MainContent;
/// <summary>
/// lblfoot control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>下面是VDS.Master的内容:
<%@ Master Language="C#" AutoEventWireup="True" CodeBehind="VDS.Master.cs" Inherits="MyApp.VDS.VDS" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Dealer Services</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<link href="Styles/master.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<div class="header">
<h1>Welcome to Dealer Services </h1>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<div class=" clear nav">
<asp:Menu runat="server" ID="NavMenu" BackColor="Silver" DataSourceID="smds1"
DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="0.8em"
ForeColor="White" Orientation="Horizontal" StaticSubMenuIndent="10px">
<DynamicHoverStyle BackColor="#284E98" ForeColor="White" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicMenuStyle BackColor="#B5C7DE" />
<DynamicSelectedStyle BackColor="#507CD1" />
<StaticHoverStyle BackColor="#284E98" ForeColor="White" />
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<StaticSelectedStyle BackColor="#507CD1" />
</asp:Menu>
<asp:SiteMapDataSource ID="smds1" runat="server" ShowStartingNode="False" />
</div>
<div class="login">
</div>
<div class="content">
<asp:ContentPlaceHolder id="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
<div class="footer">
<asp:Label runat="server" ID="lblfoot">™ Veehco Inc. 2011</asp:Label>
</div>
</div>
</form>
</body>
</html>我尝试删除VDS.Master.designer.cs文件,但每次构建时都会返回错误。我该如何纠正这个问题?
非常感谢!
发布于 2011-05-20 02:32:04
你有没有可能把它从网站转换成Web应用程序?我有时会看到这个由转换引起的问题。
VDS.master文件的第一行可能如下所示:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="VDS.master.cs" Inherits="VDS" %>问题在于,至少在我的例子中,它使用的是CodeFile属性而不是CodeBehind。如果您的项目确实是一个Web应用程序,并且上面的代码行包含CodeFile,则需要将其更改为CodeBehind,使其如下所示:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="VDS.master.cs" Inherits="VDS" %>错误的原因是由于这两个属性的处理方式:
bin
如果您的项目是一个web应用程序,但它使用的是CodeFile属性,那么它最终将由您编译,然后在运行时编译,从而产生两个不同的程序集,它们包含相同类的定义。然后一切都会爆炸。
发布于 2012-01-25 03:45:33
您是否碰巧有一个与名称空间同名的文件?
例如,主文件的名称与命名空间和项目的名称相同!
发布于 2011-05-20 06:58:04
在设计器和.master文件中,您有一个与VDS类冲突的VDS命名空间。
从以下位置更改.master中的继承:
Inherits="MyApp.VDS.VDS"至:
Inherits="MyApp.VDS"和设计器文件的位置:
namespace MyApp.VDS {至:
namespace MyApp {https://stackoverflow.com/questions/6061972
复制相似问题