The Namespace * already contains a definition for *

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="nofollow noreferrer noopener" 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!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

Method 2

Do you by any chance have a file named the same as the namespace?

For example, the master file is named the same as the namespace and the project!

Method 3

In the designer and .master file, you have a namespace of VDS which conflicts with the VDS class.

Change the inherits in the .master from:

Inherits="MyApp.VDS.VDS"

to:

Inherits="MyApp.VDS"

and the designer file from:

namespace MyApp.VDS {

to:

namespace MyApp {

Method 4

Joel is right on the mark, I had the same problem and was inclined to rename and take shortcut. But on taking time to investigate was worth reestablishing confidence with the tool.

I had an Admin class in my project in namespace MyNameSpace.

And I was trying to create MyNamespage.Admin.

I changed Admin class to Administrator and it works.

Method 5

This mean you already have 1 define VDS some where in your namespace, you must find out.
It’s usually occur because you move or edit file in VS Studio

In your case,

namespace MyApp{
public partial class VDS : System.Web.UI.MasterPage

That mean, you already define MayApp.VDS

after that. in your design

namespace MyApp.VDS {

public partial class VDS {

MyApp.VDS not a namespace, VDS is a class

so you just delete vds in your design file
now will be

namespace MyApp{

public partial class VDS {


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x