Mixing VB.NEt with CS

  • Thread starter Thread starter Rohit Sharma
  • Start date Start date
R

Rohit Sharma

Hi All,

I have a VB .NET application. I want to use one class written in CS. Can I
include the CS file and use the class in my VB app? I have tried it but I
cant seem to instantiate the class....

Cheers
Rohit
 
Hi Rohit,

You cannot include C# code in VB.NET. You need to create a new C# project
with the C# code in (as a class library), then reference your VB.NET project
to the C# project. The resulting DLL from the C# project needs to be copied
around with your app.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"


: Hi All,
:
: I have a VB .NET application. I want to use one class written in CS. Can I
: include the CS file and use the class in my VB app? I have tried it but I
: cant seem to instantiate the class....
:
: Cheers
: Rohit
:
:
 
Hello,

Rohit Sharma said:
I have a VB .NET application. I want to use one class written
in CS. Can I include the CS file and use the class in my
VB app? I have tried it but I cant seem to instantiate the class....

You will have to compile the class into a C# Class Libarary project and
reference this project from your VB.NET application.
 
Hi Rohit,

While you can't mix C# and VB within the same project, you can mix them in
the same assembly and you don't need to use a separate class library. To do
this, you need to compile your C# class as a .NetModule, then add that
module when you compile your VB app. This needs to be compiled from the
command-line, as it isn't directly supported within Visual Studio. The
command lines could be something like:

csc /t:module /out:CSharp.NetModule CSharp.cs
vb /t:exe /out:VbTest.Exe /addmodule:CSharp.NetModule VbTest.vb

NetModules are also quite cool in that they allow you to create a plug-in
architecture for your apps.

HTH,

Mark
--
Author of "Comprehensive VB .NET Debugging"
http://www.apress.com/book/bookDisplay.html?bID=128


Hi All,

I have a VB .NET application. I want to use one class written in CS. Can I
include the CS file and use the class in my VB app? I have tried it but I
cant seem to instantiate the class....

Cheers
Rohit
 
Back
Top