Is it possible to have C# and vb.net in the same asp.net website? without separating in class libraries.
6 Answers
Try this in the App_Code subfolder create 2 new subfolders, one for your C# classes and another for your VB.NET classes. After that specify these 2 folders in the web.config in the section like this:
<system.web>
<compilation debug="true">
<codeSubDirectories>
<add directoryName="CSharp"/>
<add directoryName="VB"/>
</codeSubDirectories>
</compilation>
Or you can create new project in other language and add referenc to it.

- 1,421
- 1
- 17
- 35
-
from his questions.. "...without separating in class libraries". I dont think your method works in that case. – Punit Vora Dec 29 '09 at 22:38
-
Note: A Web Application project can have an App_Code folder, a Web Site can't. (I.e. if you create a folder with that name in a Web Site it has no special meaning.) – Guffa Jan 02 '10 at 11:29
-
1Guffa, it's the other way around, isn't it? – citronas Jan 02 '10 at 23:18
No - the compiler needs code files in different languages to be compiled separately. A C# class library cannot contain VB.NET code, simply because the compiler can't distinguish which code files are written in which language.

- 58,548
- 56
- 243
- 402
-
There are lots of other file extensions too, that usually shouldn't be compiled at all. – Tomas Aschan Dec 29 '09 at 22:37
-
1The response is not no, it's "yes", we use it every day in "website". I don't think you can do this in web application, but in website you can. The only issue we have is when we use F12 (goto definition), visual studio is unable to navigate correctly between languages. But, I can have a "baseClass" written in VB, and inherit of it in C#, all in the same app_code, when using the method provided by Florim. – foxontherock Feb 18 '16 at 16:39
If you have a Web Application project, then it's possible.
If you have a Web Site project, then it's not possible.

- 687,336
- 108
- 737
- 1,005
-
1
-
1@Bassel: The Web Application project is a newer type of project. It's more like other projects, residing in the Projects folder, while a Web Site project works against a file based web site, either residing in an IIS folder, or in the Websites folder. – Guffa Dec 29 '09 at 22:24
-
2@Guffa: actually, WAP is almost identical to the original web application type. – John Saunders Dec 29 '09 at 22:39
-
1@John: What are you talking about? There are many differences, for example that the Wep Application project keeps track of exactly which files are part of the projet, while a web site simply consists of all files and folders that happens to be in the folder. – Guffa Dec 29 '09 at 23:41
-
1
-
@Raúl: Either you are talking about somehting completely different, or you are plainly wrong. The Web Site is the type of project that has existed since the first version of Visual Studio .NET. The Web Application project came two or three versions later. – Guffa Dec 30 '09 at 13:45
At a very theoretical level it is possible. As some people here have noted, it is possible to use various techniques to have multiple class libraries in the same application, each written in a different programming language. In the end it simulates the experience of writing a single application in multiple languages. I would say that most of the time that should be sufficient.
There is also a little known feature of .NET and the CLR called a "net module". See this blog post for an explanation on net modules and assemblies (and even multi-file assemblies!).
Having said all this, my first recommendation would be to just choose one language and stick to it. If that isn't an option, having multiple assemblies is a good choice. Using the App_Code trick mentioned by Florim will allow you to keep all your files in one project, even though multiple assemblies will be created on disk by ASP.NET (you'll never see them though).
If you have some worries about having multiple assemblies as opposed to multiple projects then it would be helpful to find out what the concern is. ASP.NET projects, one way or another, almost always get compiled into multiple assemblies. There are tricks to avoid that, but they are seldom used (such as the aspnet_compiler and aspnet_merge).

- 25,582
- 3
- 84
- 102
when tried I found out that you can't (by default) have different languages in a website under App_Code folder.but for other files outside (App_Code) yes you can.
to be able to have different languages under App_Code you need the technique mentioned by Florim.
thank you all guys for help.

- 1,584
- 5
- 19
- 35