By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,031 Members | 1,334 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,031 IT Pros & Developers. It's quick & easy.

Mixing VB.NEt with CS

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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"
"Rohit Sharma" <lt*************@hotmail.com> wrote in message
news:es**************@TK2MSFTNGP11.phx.gbl...
: 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
:
:
Nov 20 '05 #2

P: n/a
Hello,

"Rohit Sharma" <lt*************@hotmail.com> schrieb:
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.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #3

P: n/a
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
"Rohit Sharma" <lt*************@hotmail.com> wrote in message
news:es**************@TK2MSFTNGP11.phx.gbl...
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

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.