views:

227

answers:

6

Is it possible to have C# and vb.net in the same asp.net website? without separating in class libraries.

+4  A: 

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.

Tomas Lycken
File extension...?
Josh Stodola
There are lots of other file extensions too, that usually shouldn't be compiled at all.
Tomas Lycken
+3  A: 

If you have a Web Application project, then it's possible.

If you have a Web Site project, then it's not possible.

Guffa
what's the actual difference between the two?
Bassel Alkhateeb
@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
@Guffa: actually, WAP is almost identical to the original web application type.
John Saunders
@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
@Guffa: Web Site project is actually newer than the WAP.
Raúl Roa
@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
+2  A: 

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.

Florim Maxhuni
from his questions.. "...without separating in class libraries". I dont think your method works in that case.
desigeek
thanks for your answer,, I didn't know this technique.
Bassel Alkhateeb
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
Guffa, it's the other way around, isn't it?
citronas
+1  A: 

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).

Eilon
A: 

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.

Bassel Alkhateeb
A: 

It is not posible try in different language

Lingesh