Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

asp.net

vb.net

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?

like image 352
rafat Avatar asked Jan 18 '26 23:01

rafat


2 Answers

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

like image 58
PSK Avatar answered Jan 20 '26 13:01

PSK


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

like image 28
Aditya Singh Avatar answered Jan 20 '26 14:01

Aditya Singh