Problem with doubled namespace

Last post 11-13-2008 2:40 AM by Thomas Sun – MSFT. 4 replies.

Sort Posts:

  • Problem with doubled namespace

    11-10-2008, 11:55 AM
    • Member
      point Member
    • jovball
    • Member since 05-21-2007, 11:15 AM
    • Posts 2

    I have one c# web application that keeps generating errors in the designer.cs file after I edit an aspx page. I have built multiple web application projects and have not experienced this problem in any others. At this point, I'm deciding that I'm blind to whatever is causing this and hoping someone else will know what is causing the problem.

    I have a web app project, we'll call the Default namespace Company.Web.UI.

     

    The project is using master pages.

    namespace  Company.Web.UI
    {
    public partial class MasterPages_default

     

    The content pages reference the master page.

    <%@ Page Language="C#" MasterPageFile="~/MasterPages/default.master" AutoEventWireup="True" Inherits="Company.Web.UI.MyWebPage" title="Report Parameter Setup" Codebehind="MyWebPage.aspx.cs" %>
    <%
    @ MasterType VirtualPath="~/MasterPages/default.master" %>

     

    The content pages code-behind.

    namespace  Company.Web.UI
    {
    public partial class MyWebPage

     

    When I edit a page and build, the build will fail. Notice the doubled namespace in the error message.

    Error 61 The type or namespace name 'MasterPages_default' does not exist in the namespace 'Company.Web.UI.Company.Web.UI' (are you missing an assembly reference?) 
     

    The designer.cs file looks like this:

    /// <summary>
    /// Master property.
    /// </summary>
    /// <remarks>
    /// Auto-generated property.
    /// </remarks>
    public new Company.Web.UI.MasterPages_default Master {
    get {
    return ((Company.Web.UI.MasterPages_default)(base.Master));
    }
    }

    If I remove the namespace from the Master pages property in the designer file like the example below, the project will build. However, it happens EVERY time I make a change to an aspx page for the designer file of that page. I just can't see what is different/wrong with this project.

     public new MasterPages_default Master {
    get {
    return ((MasterPages_default)(base.Master));
    }
    }

    Any thoughts would be appreciated.

     

  • Re: Problem with doubled namespace

    11-11-2008, 5:16 AM
    Answer
    • Participant
      1,296 point Participant
    • shandyhidayat
    • Member since 11-06-2008, 2:02 PM
    • Jakarta - Indonesia
    • Posts 199

     Hi,

     try to remove all namespace Company.Web.UI 

     I think web pages don't need to use namespace.

     

     

    Regards,

    Shandy Hidayat, MCPD
  • Re: Problem with doubled namespace

    11-12-2008, 11:01 PM

    Hi,

    There is new modifier "Partial" in ASP.NET 2.0.  When we create new page in Visual Studio, it creates two partial classes for this page, one is for developer to write his own code; another is for declare code of control.

    In your case, we need to make sure these classes have same Namespace, supported interfaces, and so on.

    For more information, see http://webproject.scottgu.com/CSharp/UnderstandingCodeBehind/UnderstandingCodeBehind.aspx

     

    I look forward to hearing from you.

     

    Thomas Sun
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
  • Re: Problem with doubled namespace

    11-12-2008, 11:15 PM
    • Member
      point Member
    • jovball
    • Member since 05-21-2007, 11:15 AM
    • Posts 2

    Thomas:

     Please see my "code" above. The namespaces are the same in all .cs files (master.cs, designer.cs, etc.).

  • Re: Problem with doubled namespace

    11-13-2008, 2:40 AM
    Answer

    Hi,

    Thanks for your response. This is Namespace issue. If the classes are in the same Namespace, we don't need to use full qualifier to refer it.

    I cannot repro the issue. The following is my test code:

    MasterPages_default.Master.cs:

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

            }
        }
    }

     

    MasterPages_default.Master.designer.cs:

    namespace Company.Web.UI {
       
       
        public partial class MasterPages_default {
           
            /// <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>
            /// ContentPlaceHolder1 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 ContentPlaceHolder1;
        }
    }

    MyWebPage.aspx.cs:

    namespace Company.Web.UI
    {
        public partial class MyWebPage : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
            
            }
        }
    }

    MyWebPage.aspx.designer.cs:

    namespace Company.Web.UI
    {


        public partial class MyWebPage
        {
            public new Company.Web.UI.MasterPages_default Master
            {
                get
                {
                    return ((Company.Web.UI.MasterPages_default)(base.Master));
                }
            }
        }
    }

    If this cannot help you, please post the code just like me.

     

    I look forward to hearing from you.

    Thomas Sun
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
Page 1 of 1 (5 items)