views:

438

answers:

2

After converting a Asp.net website to web application, I receive 'Type MyNameSpace.MyMaster is not defined' error on pages that use the MasterType directive.

eg In the aspx file

<%@ MasterType VirtualPath="~/MyMaster.master" %>

In the designer.vb file the following code is generated and has the error described above:

Public Shadows ReadOnly Property Master() As MyNameSpace.MyMaster
    Get
        Return CType(MyBase.Master, MyNameSpace.MyMaster)
    End Get
End Property

If I remove the namespace the error goes away but this code is regenerated every time I make a change to the aspx page.

If I use TypeName without the namespace(eg Typename="MyMaster") instead of VirtualPath in the directive, the code is generated without the namespace reference and therefore no error. However this fails at runtime instead. Including the namespace behaves in the same way as using the VirtualPath.

I am pretty sure this has something to do with the conversion process as new web application projects do not have this problem.

Any ideas what is going on here?

UPDATE:

Problem Solved!

In the conversion process I had added a Namespace with the same name as my root Namespace to a class. Simply removed that to fix the problem.

A: 

You could namespace your masterpage class. Namespaces are created by default in web app projects.

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

        }
    }
}

Read this to find out about any other gotchas:

http://msdn.microsoft.com/en-us/library/aa730880%28VS.80%29.aspx

Steve
That does not change anything - the same problem occurs, just with the extra namespace now.
geoff
A: 

Problem Solved!

In the conversion process I had added a Namespace with the same name as my root Namespace to a class. Simply removed that to fix the problem.

geoff