Calling of C# methods from VB.Net

  • Thread starter Thread starter Muhammad Arif
  • Start date Start date
M

Muhammad Arif

Dear All,
How I can call a method of C# class from VB.Net? Suppose I have a
class SaveFile in C# having a method saveImageFile(). There is a form
Form1 in VB.Net having an picturebox populated with an image. I want
to call SaveFile.saveImageFile() method from Form1. How it will be
done?

Regares,
Arif
 
Is your C# code available in a separate DLL? What you do then is add a
reference to that particular dll. After having set that reference you simply
invoke the C# function with its name + expected parameters from VB.NET, e.g.
SaveFile.saveImageFile().

--
Regards,

Maarten Struys, eMVP
PTS Software bv

www.opennetcf.org | www.dotnetfordevices.com
 
Add your C# class to a class library project, compile it and then
reference the assembly from your VB .NET project. Very simple, yet
effective.

HTH
Neil

--
Neil Cowburn, MVP
Co-founder, OpenNETCF.org
Technologist, Content Master Ltd
Microsoft .NET Compact Framework MVP

www.opennetcf.org | www.contentmaster.com
 
Dear Milosz,
Yup, I can add C# project to my solution but how i can use it? The C#
namespace is not accessible in VB.Net project.

Regards,
Arif
 
Dear Neil,
I have compiled my C# class library and add it to VB.Net project. When
I rebuilt the solution of VB.Net project, I gave an error that
application conflict with "mscorlib.dll". I dig out this file from my
computer and placed it with my application and start the error was
resolved.
But when my other team member took the latest version of application
and compiled VB.Net project, he also got the same error and it is not
be resolved in any case.
What would be the problem with this?

Regards,
Muhammad Arif
 
Quite simple. Compile your C# class into a Dll and Add Reference to it
from your VB project and then, declare a type of the C# class
programmatically and instantiate it.

Dim o as Class1
o=new Class1
o.saveImageFile()


with regards,


J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com
 
Dear Neil,
I how i can judge that I am using .NET CF version of mscorlib?
Moreover, for what purpose this library is used?

-- Arif --
 
Expand the References node in the Solution Explorer. Select mscorlib. In
the Property Grid, copy the path of mscorlib. Open a Visual Studio .NET
Command Prompt and type the following:

sn -T <path to mscorlib.dll>

Replacing "<path to mscorlib.dll>" with the path you copied from the
Property Grid.

MSCorLib.dll contains the core .NET Compact Framework classes such as
all the .NET types, the Reflection namespace, and a whole host more.

--Neil

--
Neil Cowburn, MVP
Co-founder, OpenNETCF.org
Technologist, Content Master Ltd
Microsoft .NET Compact Framework MVP

www.opennetcf.org | www.contentmaster.com
 
Back
Top