Errors accessing .NET class method overloads in IronPython

元气小坏坏 提交于 2019-12-06 17:05:51

问题


I have a class I've written in C#. The class has two methods, the signatures being:

bool Navigate(string url)
bool Navigate(Uri url)

From what I gather, the IronPython runtime is supposed to try and select the best overload based on the passed-in argument. In my case, I'm passing in a string which I know to be non-null, yet I get the following exception:

Multiple targets could match: Navigate(Uri), Navigate(str)

Seeing as my argument is blatantly a string, why does IronPython insist that multiple targets could match? System.String does not cast to System.Uri and as such the second method overload should not be a viable candidate for selection...


回答1:


It sounds like somehow IronPython is deciding that it can convert strings to Uris. Perhaps this is a "feature", I don't know. You could do something like the following (source):

navigate_string = myObj.Navigate.Overloads[type("")]
navigate_string("asdf")


来源:https://stackoverflow.com/questions/1981566/errors-accessing-net-class-method-overloads-in-ironpython

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!