1

I am using a C# DLL from an VB project, so far I hadn't problems, but after updating DLL version I have some compilation errors when calling functions, I'm not sure if the problem comes from optional parameters or output parameters.

In short, my problem is the opposite to this one.

This is an example of function definition in DLL (if I fix this one it happens in other function calls, it's a BIG dll):

public static bool RequestCode(string countryCode, string phoneNumber, out string password, string method = "sms", string id = null, string language = null, string locale = null, string mcc = "204", string salt = "")
public static bool RequestCode(string countryCode, string phoneNumber, out string password, out string response, string method = "sms", string id = null, string language = null, string locale = null, string mcc = "204", string salt = "")
public static bool RequestCode(string countryCode, string phoneNumber, out string password, out string request, out string response, string method = "sms", string id = null, string language = null, string locale = null, string mcc = "204", string salt = "")

This is my call from VB (all of them throw error):

result = ThatLibrary.ThatClass.RequestCode(country, telephone, pass, cc, method)

Or

result = ThatLibrary.ThatClass.RequestCode(country, telephone, pass, method)

Or

result = ThatLibrary.ThatClass.RequestCode(country, telephone, pass, method, Nothing, Nothing, Nothing, "204", "")

Or

result = ThatLibrary.ThatClass.RequestCode(countryCode:=pais, phoneNumber:=telefono, password:=password, method:=metodo, id:=Nothing, language:=Nothing, locale:=Nothing, mcc:="204", salt:="")

And this is error message:

Error 3 'RequestCode' is ambiguous because multiple kinds of members with this name exist in class 'ThatClass'.

After some days looking for a soluction I'm considering moving all my project to C# but this is a huge task so I hope there's a simple solution I missed...

11
  • 1
    Don't do that. blogs.msdn.com/b/ericlippert/archive/2011/02/10/…
    – SLaks
    Commented Mar 18, 2014 at 14:18
  • 1
    I don't know, but C# has a way to specify named optional parameters. If vb.net has that, that could fix your problem. But really, you need to clean up those signatures.
    – crashmstr
    Commented Mar 18, 2014 at 14:22
  • It does. Send hate-mail to that C# programmer. Commented Mar 18, 2014 at 14:22
  • @SLaks, it's not my DLL, Hans Passant good idea, he is nice enough to give me that DLL for free though ;-). crashmstr will try that
    – K. Weber
    Commented Mar 18, 2014 at 14:29
  • 1
    @K.Weber: I think it's probably because I tested from VB with the methods defined in VB, not C#. Commented Mar 18, 2014 at 15:11

1 Answer 1

1

You have to name all your parameters for this case to work in VB. Your last method call (naming all parameters) works with the following test:

C# dll:

namespace ClassLibrary1
{
    class ThatClass
    {
        public static string RequestCode(string countryCode, string phoneNumber, out string password, string method = "sms", string id = null, string language = null, string locale = null, string mcc = "204", string salt = "") { password = ""; return ""; }
        public static string RequestCode(string countryCode, string phoneNumber, out string password, out string response, string method = "sms", string id = null, string language = null, string locale = null, string mcc = "204", string salt = "") { password = "";  response = ""; return ""; }
        public static string RequestCode(string countryCode, string phoneNumber, out string password, out string request, out string response, string method = "sms", string id = null, string language = null, string locale = null, string mcc = "204", string salt = "") { password = ""; response = ""; request = ""; return ""; }
    }
}

VB project, referencing the C# dll:

Class ThisClass
    Sub testing()
        Dim country As String = "USA"
        Dim telephone As String = "555-555-5555"
        Dim pass As String = ""
        Dim cc As String = ""
        Dim method As String = ""
        Dim test As String = ClassLibrary1.ThatClass.RequestCode(countryCode:=country, phoneNumber:=telephone, password:=pass, method:=method, id:=Nothing, language:=Nothing, locale:=Nothing, mcc:="204", salt:="")
    End Sub
End Class
2
  • I agree this should work, so I must be missing something else, I'll give it another try
    – K. Weber
    Commented Mar 18, 2014 at 16:41
  • The problem seemed to be in Visual Studio version, project making use of DLL was in Visual Studio 2008 (:-S yes!) and I went to VS2012 and it's working now
    – K. Weber
    Commented Mar 19, 2014 at 9:47

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