HOWTO: Use C# and VB in the same project

You will get a com­pi­la­tion error if you will place  C# and VB code along in App_Code direc­tory. This lit­tle code snip­pet for web.config gives your com­pliper an abil­ity to dis­tin­guish between lan­guages.  Some of you could ask, i use X lan­guage why should i start an appli­ca­tion with native sup­port for few ? Real life exam­ple explains why would you do that.

real life example:

I had to work on a project large part of which was writ­ten in VB, i do under­stand VB but i feel much more com­fort­able with C#.  I could use great tool by Devel­oper Fusion, a .NET Code Con­verter but it was much eas­ier to keep the old code and just have new one writ­ten in my native lan­guage.  This way i could uti­lize already writ­ten code inVB.

Impor­tant note, if you using VB in multi lan­guage project please write your func­tions as strict as pos­si­ble to avoid pos­si­ble com­pli­a­tion issues while use a com­bi­na­tion of func­tions from both App_Code dirs.

code:

Cre­ate two new fold­ers inside of App_Code folder, CS for C# code and VB obvi­ously for VB code.  Folder names are not impor­tant as used only as iden­ti­fiers for web.config attrib­utes in code below.


<compilation>

<codeSubDirectories>

<add directoryName="CS" />

<add directoryName="VB" />

</codeSubDirectories>

</compilation>
Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DotNetKicks
  • DZone
  • LinkedIn
  • StumbleUpon
  • Technorati
  • Live
  • PDF

Tags: ASP.NET, web.config

Leave a comment