Q&A: Using both C# and Visual Basic .NET in the same Web Application

I get quite a random set of questions coming into my Inbox from folks I meet at events, conferences and through my blog. I thought it might be useful if I started sharing my answers when these come in. To start this off, I was asked:

“We have two .NET development teams after our company acquired a smaller company. The two team use different .NET languages. We are trying to bring together two web applications into one, what options do we have?”

This sounded like one of those “which language is best” and “how do we migrate” questions – but after some probing I realised the teams did not realise how easy it was to have both languages in the same application.

The ASP.NET App_Code folder is used to store source code which ASP.NET compiles at run time into an assembly. An assembly in .NET can only be created from a single language (ok – there are some workarounds – but don’t go there). However the good news is you can specify additional sub folders, in this example one for VB and one for C#. You do this in your web.config compilation section. Once done, simple place the code in the appropriate folder and ASP.NET does the rest.

    1: <compilation debug="false">
    2:     <codeSubDirectories>
    3:         <add directoryName="VBCode" />
    4:         <add directoryName="CSCode" />
    5:     </codeSubDirectories>
    6: </compilation>

For more details check out the help :-)