简体   繁体   中英

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#. 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

在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. 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:

  1. 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.

  2. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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