CS0246: The type or namespace name ‘BaseUserControl’ could not be found (are you missing a using directive or an assembly reference?)

There’s more than one way to get an error message and I found a brilliant way to get this one.

Get this. It can come about when the Start Page of your .NET Project contains a @Register Directive to a UserControl which does not compile.

And now the embarassing part: the confession

So we have this .NET Project which contains Factory Classes which load a different set of UserControls, and Data Access Objects depending on which region is configured in web.config.

But the code written for the Jyvaskyla region (JV) is old and is not intended to be executed so we unload the JV folder from the Project before compilation. But one of the pages Dog.aspx Registers the Jyvaskyla DogBreath control which itself inherits from BaseUserControl. Like so:
%@ Register Src=”~/JV/Controls/DogParts/DogBreath.ascx” TagName=”JVDogBreath” TagPrefix=”uc2″ %

…and in my newbie ignorance to this particular .NET Project I thought that Dog.aspx was the Visual Studio Start Page for the Projec, so that’s what I selected from the Solution Explorer Context Menu.

When I hit F5 to run the Project Dog.aspx was loaded and it went on to register the magnificent JVDogBreath control which it couldn’t because the @Register Directive syntax above forces a dynamic compile of the source code, which as I told you before, does not compile.

And why doesn’t it compile ?

As the error message said, missing namespace for its base class, ‘BaseUserControl’.
The source code for the JVDogBreath starts off like so:

public class JVDogBreath : BaseUserControl
{
…etc
}

That doesn’t compile necause BaseUserControl was not referenced properly. Since it lives in the BaseDogParts namespace it should have been:

public class JVDogBreath : BaseDogParts.BaseUserControl
{
…etc
}

or else in my usings…
using BaseDogParts

Yeah, so I was ambushed by a redundant @Register Directive in combination with me setting the wrong Start Page.

Advertisements

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: