在c#中使用vb.net dll。获取“无效参数” [英] Using a vb.net dll in c#. Getting 'invalid argument'

查看:190
本文介绍了在c#中使用vb.net dll。获取“无效参数”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个奇怪的,我知道这是一个愚蠢的,但我看不到任何东西!



我有一个在VB.net中创建的DLL(不,我不能改变它!:-)),并从C#调用它。问题出现在C#中创建对象的位置,我收到的消息是有一些无效的参数。



DLL中的构造函数代码如下:

  Sub新的(ByRef连接作为IConnection)

C#中的代码是:

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

对第一行感到满意,但它在第二行给出错误消息(一些无效参数)。



我还在VB.net中创建了一个二次项目,并调用该DLL,它在那里工作正常。



我做错了什么?



提前感谢



Andy

解决方案

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

  CustomObject test = new CustomObject(ref conn); 


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#. The problems come at the point the object is created in C# and I get the message that it has "some invalid arguments".

The constructor code in the DLL is as follows:

Sub New(ByRef Connection As IConnection)

The code in C# is:

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.

What am I doing wrong?

Thanks in advance,

Andy

解决方案

In C# if a parameter is "ByRef" you have to specify it when you call the function

CustomObject test = new CustomObject(ref conn);

这篇关于在c#中使用vb.net dll。获取“无效参数”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆