Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MasterType problem after converting from ASP.Net WebSite to Web Application project

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.

like image 240
Geoff Appleford Avatar asked Nov 14 '22 15:11

Geoff Appleford


1 Answers

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(VS.80).aspx

like image 110
Steve Avatar answered Dec 18 '22 21:12

Steve