在 C# 中使用 vb.net dll。获取“无效参数”
得到了一个奇怪的东西,我知道这很愚蠢,但我看不出它有什么用!
我在 VB.net 中创建了一个 DLL(不,我无法更改它!:-))并从 C# 调用它。问题出现在用 C# 创建对象时,我收到消息说它有“一些无效参数”。
DLL 中的构造函数代码如下:
Sub New(ByRef Connection As IConnection)
C# 中的代码是:
IConnection conn = new Connection();
CustomObject test = new CustomObject(conn)
它对第一行很满意,但在第二行给出了错误消息(“一些无效参数”)。
我还在 VB.net 中创建了一个辅助项目并称为 DLL,它在那里工作得很好。
我做错了什么?
预先感谢,
安迪
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 C# 中,如果参数是“ByRef”,则必须在调用函数时指定它
In C# if a parameter is "ByRef" you have to specify it when you call the function
几天前我遇到了类似的问题,所以也许我可以帮助解决这个问题。我是新手,但在我的项目中我有同样的问题(不是错误)。
是的,您可以在 C#.NET 项目中使用通过 VB.NET 构建的 DLL。如果您有 VB.NET dll,则无需在 C#.NET 中进行任何更改即可使用它。但有时,您需要注意平台选项。
.NET 中有以下两个重要功能:
编译生成IL(中间语言)代码。所有 .NET 语言都会在编译时生成 IL,并由 JIT(即时)编译器编译。
这些语言都使用通用类型系统 (CTS) 并在相同的公共语言运行时 (CLR) 上运行。目标是生成易于互操作的代码。
所以,DLL没有问题。
您的错误可能是其他原因,我对此一无所知。
希望这有帮助。
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. If you have a VB.NET dll, you can use it without any change in C#.NET. But sometimes, you need to pay attention to platform option.
Following two important features are there in .NET:
The compilation produces IL (Intermediate Language) code. All .NET languages produces IL with at compile time is Compiled by the JIT (Just In Time) Compiler.
The languages all use a common Type System (CTS) and run on the same Common Language Runtime (CLR). The goal is to produce code which is easily interoperable.
So, DLL is not problem.
Your error may be for something else, i don't have idea about that.
Hope this helps.