该命名空间*已经包含了一个定义* [英] The Namespace * already contains a definition for *

查看:123
本文介绍了该命名空间*已经包含了一个定义*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个单独的文件夹和页面在我的ASP.NET Web应用程序。当我构建解决方案,我收到错误

I've created a separate folder and pages in my ASP.NET web application. When I build the solution, I receive the error

The Namespace MyApp already contains a defintion for VDS

下面是VDS.Master.cs的内容:

Here's the contents of 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的内容:

Here's the content of 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的内容:

Here's the content of 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">&trade; Veehco Inc. 2011</asp:Label>
</div>


</div>  


</form>
</body>
</html>

我试过删除VDS.Master.designer.cs文件,但在每一个版本则返回错误。我该如何纠正这一问题?

I've tried deleting the VDS.Master.designer.cs file, but the error is returned upon each build. How do I rectify this issue?

谢谢了!

推荐答案

你从一个网站转换到一个Web应用程序的任何机会呢?我见过造成的转换有时这个问题。

Any chance you converted it to a Web Application from a Web Site? I've seen this problem caused by the conversion sometimes.

您VDS.master文件的第一行可能看起来像这样:

The first line of your VDS.master file probably looks something like this:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="VDS.master.cs" Inherits="VDS" %>

问题,在我的情况,至少是,它使用 codeFILE 属性代替 codeBehind 。如果您的项目确实是一个Web应用程序及以上的线路中包含 codeFILE ,你会想要将它更改为 codeBehind ,所以它看起来是这样的:

The problem, in my case at least, was that it was using the CodeFile attribute instead of CodeBehind. If your project is indeed a Web Application and your line above contains CodeFile, you'll want to change it to CodeBehind so it looks something like this:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="VDS.master.cs" Inherits="VDS" %>

的原因错误是由于这两个属性的处理方式:

The reason for the error is due to the way these two attributes are handled:


  • codeBehind:需要编译
    之前部署和
    编译的程序集放在垃圾桶
    您的网站的文件夹中。

  • codeFILE:您部署源和它编译
    因为它是需要的。编译
    组件放置在临时
    ASP.NET文件夹中。

如果您的项目是一个Web应用程序,但它使用的是codeFILE属性,它最终被你们编译,然后在运行时以及导致其containg为相同的类定义的两个不同的程序集编译。然后一切爆炸。

If your project is a web application but it is using the CodeFile attribute, it ends up being compiled by you, then compiled at runtime as well resulting in two different assemblies which containg definitions for the same classes. Then everything explodes.

这篇关于该命名空间*已经包含了一个定义*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆