Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The Namespace * already contains a definition for *

Tags:

c#

asp.net

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

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)
    {

    }
}
}

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>

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>

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

Thanks much!

like image 786
SidC Avatar asked May 19 '11 16:05

SidC


1 Answers

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

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

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

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: Needs to be compiled before being deployed and the compiled assembly is put in the bin folder of your website.
  • CodeFile: You deploy the source and it is compiled as it is needed. The compiled assembly is placed in the Temporary ASP.NET folder.

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.

like image 93
Joel Beckham Avatar answered Nov 14 '22 23:11

Joel Beckham