4
votes
  • IDE: VS2010
  • Framework.net: 4.0

I created a c# dll project under 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 c# dll, but impossible to import the c# classes. The namespace of the c# dll is even not recognized.

What must I do to see my c# classes? If this is possible.

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

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

Example in a file of my vb.net dll:

Imports MyCSharpDll.MyCSharpNamespace

VS2010 indicates an error saying that MyCSharpDll is unknown or no public member.

Thank you.

4

4 Answers

4
votes

I think you should rewrite your imports

Imports MyCSharpNamespace

without 'MyCSharpDll' part

4
votes

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

YES you can do it.

Just add to that DLL reference and that's it!

4
votes

Assuming the dll in question is CLS compliant and compiled against the same runtime version, you should be able to use it without a problem.

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 as defined in the assembly metadata - look at your C# project properties to see what the default namespace is, that's what you need to import.

1
votes

You need to add a reference 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()