0

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
  • IConnection conn = new Connection(); CustomObject test = new CustomObject(ref conn) maybe ?
    – Steve B
    Commented Apr 19, 2011 at 8:51

2 Answers 2

2

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

CustomObject test = new CustomObject(ref conn);
0
0

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.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.