Is it possible to import C # classes from dll to vb.net dll?

  • IDE: VS2010
  • Framework.net: 4.0

I created a C # dll project in Visual Studio 2010 with several public classes, and I would like to use its classes inside another dll project, but written in vb.net.

In the vb.net dll project, I referenced the built-in C # dll, but it was not possible to import C # classes. The C # dll namespace is not even recognized.

What should I do to see my C # classes? If possible.

Example class of my C # dll (namespace MyCSharpDll):

namespace MyCSharpNamespace { public class MyCSharpClass { public void Test() {} } } 

An example in my vb.net dll file:

 Imports MyCSharpDll.MyCSharpNamespace 

VS2010 indicates an error indicating that MyCSharpDll is unknown or does not have an open item.

Thanks.

+4
source share
4 answers

I think you should rewrite your import

Import MyCSharpNamespace

without the part "MyCSharpDll"

+4
source

Assuming the dll in question is compatible with the CLS and compiled against the same version of the runtime, you can use it without problems.

If either (or both) of these conditions are not met, you will not be able to use the imported DLL.

Make sure the Import directive uses the namespace defined in the assembly metadata - look at your C # project properties to find out what the default namespace is, what you need to import.

+4
source

You asked: "I created a C # DLL project for Visual Studio 2010, with several public classes, and I would like to use my classes in another project dll, but it is written in vb.net."

YES, you can do it.

Just add a link to this dll and it!

+3
source

You need to add a link to your C # dll.

http://msdn.microsoft.com/en-us/library/wkze6zky%28v=vs.80%29.aspx

Now you can instantiate a C # class from VB.NET:

 Dim cClass = New MyCSharpNamespace.MyCSharpClass() 
+1
source

Source: https://habr.com/ru/post/1396834/


All Articles