Click here to Skip to main content
13,152,289 members (40,518 online)
Click here to Skip to main content
Add your own
alternative version


17 bookmarked
Posted 5 Aug 2004

Calling C# assembly functions having same name differing only by case, in VB.NET

, 5 Aug 2004
Rate this:
Please Sign up or sign in to vote.
Calling C# assembly functions having same name differing only by case, in VB.NET.


I faced this issue today. I wanted to call a function written in C# from my VB.NET code, but I found out that the coder of the library had not followed Microsoft guidelines for interoperability and had used same name for two functions differing only by case having the same signature. I didn't have access to the C# code, so was helpless as VB.NET does not allow me to use any of these functions. It gives a compile time error:

Overload resolution failed because no accessible 'f<function> is most specific for these arguments: <function names> : Not most specific


In this case, we need to use Reflection. At least, I could only find this solution.

Suppose my C# assembly code looks like the following:

namespace CompTest
  /// <summary>
  /// Summary description for Class1.
  /// </summary>
  public class Class1
    public string cameLate()
      return "He came late";

    public string camelAte()
      return "Camel Ate Him";

We can call the function camelAte in VB.NET as follows:

Dim CSClass As New CompTest.Class1
Dim ReturnValue As Object
ReturnValue = CSClass.GetType.InvokeMember("camelAte", _
              System.Reflection.BindingFlags.Instance Or _
              BindingFlags.Public Or BindingFlags.InvokeMethod, _
              Nothing, CSClass, Nothing, Nothing, Nothing, Nothing)
TextBox1.Text = ReturnValue

InvokeMember function used here Invokes the specified member, using the specified binding constraints and matching the specified argument list. You can find more information on MSDN.

To pass parameters, create an array of Object. Insert parameters required to call the function in the array. Pass the array as a parameter in the InvokeMethod function.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
GuyThiebaut13-Jul-12 6:25
memberGuyThiebaut13-Jul-12 6:25 
GeneralPerhaps another solution Pin
Enadan2614-Feb-06 5:37
memberEnadan2614-Feb-06 5:37 
GeneralGood trick but anybody who uses same name/diff case should be shot Pin
Rhelic12-Aug-04 3:04
memberRhelic12-Aug-04 3:04 
GeneralUseful trick Pin
Nishant S6-Aug-04 18:26
staffNishant S6-Aug-04 18:26 
GeneralRe: Useful trick Pin
Manish K. Agarwal7-Aug-04 2:15
memberManish K. Agarwal7-Aug-04 2:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170924.2 | Last Updated 6 Aug 2004
Article Copyright 2004 by r@hu!
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid