从VB调用C#dll

从VB调用C#dll,c#,.net,vb.net,dll,C#,.net,Vb.net,Dll,我使用的是一个VB项目中的C#DLL,到目前为止我没有问题,但在更新DLL版本后,调用函数时出现了一些编译错误,我不确定问题是来自可选参数还是输出参数 简言之,我的问题与之相反 这是DLL中函数定义的一个示例(如果我修复了这个,它会发生在其他函数调用中,这是一个大DLL): 这是我从VB发出的调用(所有调用都抛出错误): 或 或 或 这是一条错误消息: 错误3“RequestCode”不明确,因为类“ThatClass”中存在多种具有此名称的成员 在寻找解决方案几天后,我正在考虑将我所有的项目移

我使用的是一个VB项目中的C#DLL,到目前为止我没有问题,但在更新DLL版本后,调用函数时出现了一些编译错误,我不确定问题是来自可选参数还是输出参数

简言之,我的问题与之相反

这是DLL中函数定义的一个示例(如果我修复了这个,它会发生在其他函数调用中,这是一个大DLL):

这是我从VB发出的调用(所有调用都抛出错误):

这是一条错误消息:

错误3“RequestCode”不明确,因为类“ThatClass”中存在多种具有此名称的成员


在寻找解决方案几天后,我正在考虑将我所有的项目移到C#上,但这是一项艰巨的任务,所以我希望有一个简单的解决方案我错过了…

您必须命名所有参数,以便在VB中工作。 最后一次方法调用(命名所有参数)可用于以下测试:

C#dll:

VB项目,参考C#dll:


不要那样做。我不知道,但C#有一种指定命名可选参数的方法。如果vb.net有这个功能,就可以解决您的问题。但真的,你需要清理那些签名。确实如此。给那个C#程序员发封仇恨邮件。@SLaks,这不是我的DLL,Hans Passant好主意,他很好,免费给了我那个DLL;-)。crashmstr会试试的that@K.Weber:我想这可能是因为我使用VB中定义的方法而不是C#从VB中进行测试。我同意这应该是可行的,所以我肯定错过了其他东西,我将再试一次。问题似乎出现在Visual Studio版本中,使用DLL的项目出现在Visual Studio 2008中(:-s是!)我去了VS2012,它现在开始工作了
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 = "")
result = ThatLibrary.ThatClass.RequestCode(country, telephone, pass, cc, method)
result = ThatLibrary.ThatClass.RequestCode(country, telephone, pass, method)
result = ThatLibrary.ThatClass.RequestCode(country, telephone, pass, method, Nothing, Nothing, Nothing, "204", "")
result = ThatLibrary.ThatClass.RequestCode(countryCode:=pais, phoneNumber:=telefono, password:=password, method:=metodo, id:=Nothing, language:=Nothing, locale:=Nothing, mcc:="204", salt:="")
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 ""; }
    }
}
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