Calling ByRef from VB.NET

  • Thread starter Sjur Rondestveit
  • Start date
S

Sjur Rondestveit

I have a DLL created in C# with a method that takes a string by
reference (public bool NoError(DataSet ds, ref string msg)).
When I try to call the method from VB.NET (NoError(ds, m_sMessage)), I
get a "System.MissingMethodException: Method not found: Boolean
NoError(System.Data.DataSet, System.String)".

In C# you must state that you are calling a method by reference, but
can you do this in VB.NET?

Thanks in advance.

Yours sincerely,
Sjur Rondestveit
 
H

Herfried K. Wagner [MVP]

Sjur Rondestveit said:
I have a DLL created in C# with a method that takes a string by
reference (public bool NoError(DataSet ds, ref string msg)).
When I try to call the method from VB.NET (NoError(ds, m_sMessage)), I
get a "System.MissingMethodException: Method not found: Boolean
NoError(System.Data.DataSet, System.String)".

In C# you must state that you are calling a method by reference, but
can you do this in VB.NET?


There must be another reason for the error message. 'ref' in C# is
"syntactic sugar". Parameters are passed by reference if the method
declares them using 'ref'/'ByRef'. The documentation on
'MissingMethodException' lists some possible reasons for the exception being
thrown.
 
P

Phill. W

Sjur Rondestveit said:
I have a DLL created in C# with a method that takes a string by
reference (public bool NoError(DataSet ds, ref string msg)).
When I try to call the method from VB.NET ... I get a
"System.MissingMethodException: Method not found: Boolean
NoError(System.Data.DataSet, System.String)".

Run ildasm on the C# Dll. Make sure that your method appears.

Also, ensure the AssemblyVersion attribute in the C# project is
set explicitly ("1.0.0.0", or similar) and /not/ left at [the default]
"1.0.*".
If you're loading the assembly from the Global Assembly Cache,
you could be picking up an "old" version of it (with some /very/
odd-looking version numbers!).

HTH,
Phill W.
 
S

Sjur Rondestveit

Phill. W said:
Sjur Rondestveit said:
I have a DLL created in C# with a method that takes a string by
reference (public bool NoError(DataSet ds, ref string msg)).
When I try to call the method from VB.NET ... I get a
"System.MissingMethodException: Method not found: Boolean
NoError(System.Data.DataSet, System.String)".

Run ildasm on the C# Dll. Make sure that your method appears.

Also, ensure the AssemblyVersion attribute in the C# project is
set explicitly ("1.0.0.0", or similar) and /not/ left at [the default]
"1.0.*".
If you're loading the assembly from the Global Assembly Cache,
you could be picking up an "old" version of it (with some /very/
odd-looking version numbers!).

HTH,
Phill W.
Thanks, that's it. Other DLL's in the same project were also using the
C#-DLL and since the AssemblyVersion was different things got pretty
messed up.

Thanks alot :)

Yours sincerely,
Sjur Rondestveit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top