Initializes an instance of the AmbiguousMatchException class.
Initializes an instance of AmbiguousMatchException with an empty message string and the root cause exception set to null.
[Visual Basic] Overloads Public Sub New()
[C#] public AmbiguousMatchException();
[C++] public: AmbiguousMatchException();
[JScript] public function AmbiguousMatchException();
Initializes an instance of AmbiguousMatchException with its message string set to the given message and the root cause exception set to null.
[Visual Basic] Overloads Public Sub New(String)
[C#] public AmbiguousMatchException(String);
[C++] public: AmbiguousMatchException(String*);
[JScript] public function AmbiguousMatchException(String);
Initializes an instance of AmbiguousMatchException with its message string set to the given message and the given root cause exception.
[Visual Basic] Overloads Public Sub New(String, Exception)
[C#] public AmbiguousMatchException(String, Exception);
[C++] public: AmbiguousMatchException(String*, Exception);
[JScript] public function AmbiguousMatchException(String, Exception);
In the example shown below, two classes are constucted, each named Mymethod. One class takes a integer and one a string. If an integer is passed to Mymethod, the first class is used. If a string is passed, the second class is used. If it cannot determine which Mymethod to use, the exception is thrown.
Note This example shows how to use one of the overloaded version of the AmbiguousMatchException constructor. For other examples that may be available, see the individual overload topics.
class Myambiguous{ //The first overload is typed to an Int32 public static void Mymethod (Int32 number){ Console.Write("\n{0}", "I am from Int32 method"); } //The second overload is typed to a string public static void Mymethod (string alpha){ Console.Write("\n{0}", "I am from a string."); } public static void Main() { try{ //The following does not cause as exception Mymethod (2); // goes to Mymethod (Int32) Mymethod ("3"); // goes to Mymethod (string) Type Mytype = Type.GetType ("Myambiguous"); MethodInfo Mymethodinfo32 = Mytype.GetMethod("Mymethod", new Type[]{typeof(Int32)}); MethodInfo Mymethodinfostr = Mytype.GetMethod("Mymethod", new Type[]{typeof(System.String)}); //Invoke a method, utilizing a Int32 integer Mymethodinfo32.Invoke(null,new Variant[]{2}); //Invoke the method utilizing a string Mymethodinfostr.Invoke(null,new Variant[]{"1"}); //The following line causes an ambiguious exception MethodInfo Mymethodinfo = Mytype.GetMethod("Mymethod"); } // end of try block catch(System.Reflection.AmbiguousMatchException theException){ Console.Write("\nAmbiguousMatchException message - {0}", theException.Message); } catch { Console.Write("\nError thrown"); } return; } } Produces the following output I am from Int32 method I am from a string. I am from Int32 method I am from a string. AmbiguousMatchException message - Ambiguous match found.
AmbiguousMatchException Class | AmbiguousMatchException Members | System.Reflection Namespace