简体   繁体   English

在c#中使用vb.net dll。 获得'无效论证'

[英]Using a vb.net dll in c#. Getting 'invalid argument'

Got a strange one and I know it is something silly but I can't see it for anything! 有一个奇怪的,我知道它是愚蠢的东西,但我什么都看不到它!

I have a DLL created in VB.net (No I can't change it! :-)) and am calling it from C#. 我有一个在VB.net中创建的DLL(不,我不能改变它!:-))并且我从C#调用它。 The problems come at the point the object is created in C# and I get the message that it has "some invalid arguments". 问题来自于在C#中创建对象,我得到的消息是它有“一些无效的参数”。

The constructor code in the DLL is as follows: DLL中的构造函数代码如下:

Sub New(ByRef Connection As IConnection)

The code in C# is: C#中的代码是:

IConnection conn = new Connection();  
CustomObject test = new CustomObject(conn)

It is happy with the first line but it gives the error message ("some invalid arguments") on the second line. 它对第一行感到满意,但它在第二行给出了错误消息(“一些无效的参数”)。

I have also created a secondary project in VB.net and called the DLL and it works fine there. 我还在VB.net中创建了一个辅助项目并调用了DLL,它在那里工作正常。

What am I doing wrong? 我究竟做错了什么?

Thanks in advance, 提前致谢,

Andy 安迪

在C#中,如果参数是“ByRef”,则必须在调用函数时指定它

CustomObject test = new CustomObject(ref conn);

I had the similar problem before few days so may be i can help with this. 几天前我遇到了类似的问题,所以我可以帮忙解决这个问题。 I am newbie but in my project i had the same question (not error). 我是新手但在我的项目中我有同样的问题(不是错误)。

Yes, you can use a DLL built via VB.NET in a C#.NET project. 是的,您可以在C#.NET项目中使用通过VB.NET构建的DLL。 If you have a VB.NET dll, you can use it without any change in C#.NET. 如果你有一个VB.NET DLL,你可以在没有任何C#.NET更改的情况下使用它。 But sometimes, you need to pay attention to platform option. 但有时候,你需要注意平台选项。

Following two important features are there in .NET: 以下两个重要功能在.NET中:

  1. The compilation produces IL (Intermediate Language) code. 编译产生IL(中间语言)代码。 All .NET languages produces IL with at compile time is Compiled by the JIT (Just In Time) Compiler. 所有.NET语言在编译时生成IL由JIT(即时)编译器编译。

  2. The languages all use a common Type System (CTS) and run on the same Common Language Runtime (CLR) . 这些语言都使用通用类型系统(CTS)并在相同的公共语言运行时(CLR)上运行 The goal is to produce code which is easily interoperable. 目标是生成易于互操作的代码。

So, DLL is not problem. 所以,DLL不是问题。 Your error may be for something else, i don't have idea about that. 你的错误可能是其他的,我不知道。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM