问题
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
回答1:
In C# if a parameter is "ByRef" you have to specify it when you call the function
CustomObject test = new CustomObject(ref conn);
回答2:
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.
来源:https://stackoverflow.com/questions/5713818/using-a-vb-net-dll-in-c-getting-invalid-argument