Is it possible to import c# classes from dll in a

2019-05-06 03:43发布

  • 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条回答
祖国的老花朵
2楼-- · 2019-05-06 04:07

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.

查看更多
对你真心纯属浪费
3楼-- · 2019-05-06 04:18

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!

查看更多
Deceive 欺骗
4楼-- · 2019-05-06 04:19

I think you should rewrite your imports

Imports MyCSharpNamespace

without 'MyCSharpDll' part

查看更多
疯言疯语
5楼-- · 2019-05-06 04:20

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()
查看更多
登录 后发表回答