【发布时间】:2014-03-18 14:15:43
【问题描述】:
我正在使用来自 VB 项目的 C# DLL,到目前为止我没有问题,但是在更新 DLL 版本后,我在调用函数时出现了一些编译错误,我不确定问题是来自可选参数还是输出参数。
简而言之,我的问题与this one相反。
这是 DLL 中函数定义的一个示例(如果我修复了这个,它会发生在其他函数调用中,它是一个 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 = "")
这是我从 VB 打来的电话(它们都抛出错误):
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:="")
这是错误信息:
错误 3“RequestCode”不明确,因为在“ThatClass”类中存在多种具有此名称的成员。
在寻找解决方案几天后,我正在考虑将我的所有项目转移到 C#,但这是一项艰巨的任务,所以我希望有一个我错过的简单解决方案......
【问题讨论】:
-
我不知道,但是 C# 有一种方法可以指定命名的可选参数。如果 vb.net 有这个,那可以解决你的问题。但实际上,您需要清理这些签名。
-
确实如此。向那个 C# 程序员发送仇恨邮件。
-
@SLaks,这不是我的 DLL,Hans Passant 是个好主意,不过他很乐意免费给我那个 DLL ;-)。 crashmstr 会尝试的
-
@K.Weber:我认为这可能是因为我使用 VB 中定义的方法在 VB 中进行了测试,而不是 C#。