views:

499

answers:

2

Flawed as I am, I've received some unneeded help in creating errors in the form of Visual Studio 2008 adding incorrect code to a .designer.cs file. I appreciate, it is probably doing this because of my omission or error - but I will use the excuse that I am in actuality a fledgeling ASP.NET developer so I'm still learning.

The relevant parts of the solution exporer look like this:

/Prototypes
  /Project01.Master
   - Project01.Master.cs
   - Project01.Master.designer.cs
  /SampleApplication.aspx
   - SampleApplication.aspx.cs
   - SampleApplication.aspx.designer.cs

I'm not entirely sure which files to include in the question, so I'll try and guess as best I can. Both the .Master.cs and SampleApplication.aspx.cs include themselves within the Project01.Prototypes namespace (though I'm not precious about that, it's something that was auto-added and worked while I didn't need to think about it).

At the top of SampleApplication.aspx is the following (to enable access to some properties that the Master Page in theory, exposes.

<%@ Page Language="C#" MasterPageFile="~/Prototypes/Project01.Master" AutoEventWireup="true" CodeBehind="SampleApplication.aspx.cs" Inherits="Project01.Prototypes.SampleApplication" %>
<%@ MasterType VirtualPath="~/Prototypes/Project01.Master" %>

Within the SampleApplication.aspx.designer.cs is:

namespace Project01.Prototypes {

  public partial class SampleApplication {

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

All this results in the error:

The type name 'Prototypes' does not exist in the type 'Project01.Prototypes.Project01'

I can fix this error and get the build going again by getting rid of the 'Project01.Prototypes.' references within the class itself (leaving the namespace). My problem is that this is only a temporary solution as Visual Studio keeps adding it back in - so I guess the question is where is my mistake actually located?

p.s. If it's important, I'm running in Visual Studio 2008 with a ASP.NET MVC Web Application.

A: 

Have you tried closing down VS 2008, and then opening your project again? That normally does it for me.

waqasahmed
This doesn't work for me, as this question is the result of a few days of frustration inbetween which, I totally shutdown my PC. The issue on my part is that I don't know what exactly is the code to revert/change as it happens infrequently.
Amadiere
+3  A: 

The problem is that your top-level namespace and your master page class have the same name. So when the compiler tries to resolve the type, it's looking for a type "Prototypes.Project01" inside your master page class.

I would recommend using the typename property on the mastertype directive instead of virtualpath, but the parser seems to choke when you use a qualified type name there. So as I see it you have two alternatives:

  1. Rename your master page. Using the project name seems like it could cause confusion anyway.
  2. Don't use the mastertype directive and declare the Master property in your codebehind file manually.
zinglon
I've had a bit of a mess around and renamed the Master file to Project01Theme for now, changed the references and so on and its all compiling well now - including the lines that previously required changing. I see the flaw in what I was doing now - glad I posted this question though as I might have been a while in spotting it!
Amadiere