18

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...

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
Nathan Ridley
  • 33,766
  • 35
  • 123
  • 197
  • Interesting, not had this problem myself nor would I know how to advise though I'm afraid. – Finglas Dec 30 '09 at 18:17
  • 1
    @Nathan, I couldn't reproduce the problem. I used your two signatures, and it worked as expected. I'm using IronPython 2.6 Final. – dan-gph Jan 01 '10 at 14:45
  • There's obviously some other kind of weirdness going on in the rest of my class then. I found a workaround in the meantime, but my class is a bit too tied to my framework to easily publish it here for testing. – Nathan Ridley Jan 01 '10 at 17:40

1 Answers1

4

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")
CrazyCasta
  • 26,917
  • 4
  • 45
  • 72