Ambiguous extension method

I would strongly suggest that you rename one of the extension methods. Depending on what else you do, you could possibly just remove the using directive for one of those namespaces, but that won't help if you need both namespaces for other things. (This leads to a suggestion to put extension methods in their own namespace, of course.) Renaming is likely to simplify things in general though.


Just in case somebody will need this...

Ambiguity can be resolved if concurrent namespaces which have extension methods with same name, are included at different levels (most inner included namespace will have priority).

For example:

using Namespace1;
namespace MyApplication 
{
    using Namespace2;
    ...
    db.Execute(); // Namespace2 Execute() will be called
}

  1. Remove the ambiguity by redefining or eliminating one of the methods at the source. You don't need redundancy.
  2. If you do not control the source, include only one of them in your class file via the using directive.
  3. If you still need both namespaces in the given class file, invoke the version you wish simply as a static class call, unambiguously identifying the method via the (potentially fully qualified) class name.
 Abc.Xyz.ExtensionsClass.NoNull(database.ExecuteScalar(), string.Empty);
 // <Abc.Xyz.> is only necessary if the classes themselves match names
 // if not, only <ClassName>.<MethodName> is needed

Tags:

C#

.Net