Compiling VB and C# in ASP.Net 2.0

Anyone who ever had to integrate both C# and Vb.Net code in ASP.Net 1.0/1.1 knows how awkward and time-comsuming it could get sometimes. As much as I love the command prompt and  vbc and csc, it was never much fun guessing in which dll each control was defined.

No worries though for those days are gone! ASP.Net 2.0 makes it really easy to work with mixed code.

The only limitation of working with mixed code is that the files cannot be thrown together on the App_Code folder. You have to separate them into different folders. I think this is actually a good thing cuz it encourages good organization practices.

So, in your App_Code folder, create one folder called C# and another called VB (you can name it anything you want actually). Now, put all code files in their respective folder according to the language you used to program them.

Now all you have left to do is open your Web.Config file (or create one at the root of your web app if you don’t have one in your project yet) and do some (very simple) XML editing.

If you let Visual Studio create your Web.Config root file for you then you should already have a section. If not you’ll need to create one. This is where you can specify folders that need to be compiled separately. You don’t even need to specify the language to use for different folders, the compiler is smart enough to figure it out himself. So, all you need is to use the <codesubdirectories> element and add entries for the VB and the C# folders like this:

 

<compilation>
<codesubdirectories>
<add directoryname=”VB”>
<add directoryname=”C#”>
</codesubdirectories>
</compilation>

Note that the default Web.Config created by Visual Studio already contains a compilation section so just need to change it. Also it probably has an attribute in the compilation element of debug=”true” which is irrelevant here and that’s why it wasn’t included in the code above.

Oh and don’t forget that in ASP.Net you can always have as many Vb.Net and C# web forms as you fancy all mixed in without needing to do a thing.

Now that is a big step towards .Net’s self-imposed objective of language independance!

Unrecognized tag prefix or device filter ‘asp’. – Keep both the nested master page and the content page open on VS 2005

Whilst many people run into this design-time error in Visual Studio, the “solution” to the problem is not very wide spread.

If you are building a ASP.Net project and you get this message you are most likely using Nested Master Pages. If not then you got a bigger problem I’m afraid such as maybe the installation of VS is corrupted or, for some bizarre reason, you are missing a reference to System.Web on your ASP.Net project which is very unlikely, but hey, VS can be stupid after all as we all know.

And this is exactly the case here. As you know, visual studio is not very friendly at all with pages that derived from nested masters. You lose your design-view and you’re forced to code everything by hand on the content page. Moreover, sometimes you might see the error Unrecognized tag prefix or device filter ‘asp’. on your content page and you will lose Intellisense on it for every ASP.net-related control and the hints will be filtered by HTML tags only.

Whilst you can’t get around the former, you can fix the latter. Just keep your master page file open on VS while working with your content page and voila! error’s gone and you can use Intellisense again! You don’t need to keep both the parent master and the nested master, just the one the content page inherits from will do.