3

I just received the following compile time error in C#:

Ambiguous invocation:
      string GetDescription(this LibA.enum_contact) in LibA
      string GetDescription(this LibB.enum_contact) in LibB

It is clear what it means, but since I need to use both libraries and they are closed source, I wonder what a proper workaround would be. I can think of the following in the using code:

  • Split source file into two partials, but not sure this will not yield the same error (are using directives in scope per file, or per code unit?)
  • Create a wrapper for these extension methods
  • Call the extension method with a fully qualified name as normal method
  • or, in addition, redefine the class name with a using-directive to make this less a pain

Neither of these seem to be fully satisfactory. In some OO languages, it is possible to limit to some granularity what you accept, or, for instance in Eiffel, to rename a method when you import it and there is a name collision. I would love to be able to do:

using LibA rename ClassA.GetDescription to GetMyDescription
using LibB rename ClassB.GetDescription to GetDescriptionB

But I don't believe I've seen such a method for C# up until 6.0. I.e., you can rename a classname, but not a method name.

Does anybody have a better idea than the suggestions above?

Abel
  • 56,041
  • 24
  • 146
  • 247
  • You might want to take a look at this question: http://stackoverflow.com/questions/453451 – Dennis_E Sep 15 '15 at 09:41
  • Thanks, @Dennis_E, the [second post there by Jon Skeet](http://stackoverflow.com/a/453904/111575) shows indeed what happens here. And his suggestion is to go with the non-extension method syntax to overcome the name conflict (my option 3 above). – Abel Sep 15 '15 at 09:55
  • 1
    The non-extension method syntax would be a lot easier. If it's only 2 methods, I'd just write 2 wrapper methods. – Dennis_E Sep 15 '15 at 09:59

0 Answers0