Archive for November, 2010

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

November 25, 2010

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

BTWT Officially ‘Interesting’

November 16, 2010

The many fanatically devoted fans of BTWT have noted with a sense of justice that BTWT is finally getting the recognition it deserves as a hard-hitting, world-class Blog thing.

Proof came in the listing of BTWT at the TOP of the certainly not randomly generated ‘Interesting Blogs’ section of HoianToday which advertises the eBook ‘Digging Into WordPress’.

So now the unsolicited testimonials to BTWT include ‘somewhat funny’ and ‘interesting’.

In your face Blogosphere.

SQL Server 2005 No Corresponding BEGIN TRANSACTION

November 3, 2010

This one turned out to be yet another highly misleading error message. It also only depleted me of about 24 mins of life-force, so therefore does not strictly qualify as a Journey Of Pain, but what the heck, with my insatiable public constantly demanding more material sometimes quality is compromised.

In the beginning was a tiny SQL Script no more than 10 lines or so; and this script had one purpose in life and that was to add a new NOT NULL column to an existing table: I will call it BRUCE, tblBruce to be precise. So here is the script:

BEGIN TRAN
BEGIN TRY
ALTER TABLE tblBruce ADD IsMandatory BIT NOT NULL
END TRY

BEGIN CATCH
ROLLBACK;
END CATCH

COMMIT;

..and that friends will return you the highly misleading error message “No Corresponding BEGIN TRANSACTION”.

It lies…while not making me quite as angry as the spurious reasons advanced for the Australian Intervention in East Timor in 1999, does tee me off a bit. I’d rate it a ‘Laksa stain on my tie while eating lunch’ – grade tee-off.

The real error is that I have not specified a DEFAULT VALUE for the new column. Because the column is new no values exist for the existing rows, and because we have specified NOT NULL we have to provide a DEFAULT VALUE for all those existing rows, like so:

BEGIN TRAN
— Add new column to Bruce with default value
BEGIN TRY
ALTER TABLE tblBruce ADD IsMandatory BIT NOT NULL DEFAULT 0
END TRY
BEGIN CATCH
ROLLBACK;
END CATCH
COMMIT;

So when adding a new NOT NULL column to an existing table, provide a default value for the existing rows and you will be spared 24 mins of Laksa-stain grade ennui.

You know it makes sense.