rafat
rafat

Reputation: 817

Is it possible to add some VB class in asp.net[c#] project?

I am using asp.net [C#] in a project. It is a big project including of classes. I need to add some VB class to achieve some calculation. Is it possible to Call a VB class from C# code?

Upvotes: 3

Views: 685

Answers (4)

PSK
PSK

Reputation: 17943

I am not denying the fact mentioned in all other answers that we can’t mix languages in same project. Best approach will be to create a separate library and use that as a reference in your project. Which will be easier to implement and better approach in terms of maintainability.

But in case of an ASP.NET Website we can definitely use multiple classes from different language. To achieve this we can configure our webapplciation to create subfolders of the App_Code folders as separate compliable units and each folder can then contain source code in different programming language.

You can change your configuration file as following.

enter image description here

Once done add respective classes for the defined languages in the folders. C# in the CSCode folder and VB in the VBCode folder as following.

enter image description here

Finally you can use it in other area of your website as following.

enter image description here

Upvotes: 5

Aditya Singh
Aditya Singh

Reputation: 9612

Just add a reference of your VB project inside your C# project and use the class.

Because both VB.NET and C# compile into IL (intermediate language), you can simply create a library (a DLL file) in VB.NET, and then use that library in C#.

Upvotes: 3

Damith
Damith

Reputation: 63065

  1. Add VB.net Class library project to your C# solution.

  2. Add all the VB.net classes to that class library

  3. Add reference to VB.Net class library project from C# project

Upvotes: 2

G. Stoynev
G. Stoynev

Reputation: 7783

No - you cannot mix languages in SAME project - to answer the question in your title.

what you could do is reference the VB assembly containing that class.

Upvotes: 0

Related Questions