简体   繁体   中英

Error in Masterpage, namespace already exists

I want to add some code into my masterpage. So I removed the namespace but when I want to test it it gives this error. No idea how to fix this.

Error 2 The namespace 'Project' in 'c:\\Users\\Test\\AppData\\Local\\Temp\\Temporary ASP.NET Files\\project\\fe95a550\\6aff5a12\\assembly\\dl3\\9f54421a\\e011b011_23bccd01\\Project.DLL' conflicts with the type 'Project' in 'c:\\Users\\Test\\AppData\\Local\\Temp\\Temporary ASP.NET Files\\project\\fe95a550\\6aff5a12\\App_Web_exfemb4u.dll' c:\\Users\\Test\\AppData\\Local\\Temp\\Temporary ASP.NET Files\\project\\fe95a550\\6aff5a12\\App_Web_hrdlxq5l.4.cs 154

Masterpage.cs

public partial class Project: System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
}

Masterpage

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

Can you add a namespace before public partial ....

namespace Test
{
    public partial class MovieMeter : System.Web.UI.MasterPage
    {
         protected void Page_Load(object sender, EventArgs e)
         {
         }
    }
}

Why did you remove the namespace ? please add one.

Replace:

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

With:

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

It might solve...

Then 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.

Change your master page's name to something other than Project . as your project's name as well as you master page are name Project . It is creating conflict.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM