AmbiguousMatchExceptionとは? わかりやすく解説

AmbiguousMatchException クラス

メンバへのバインド時に、バインディング基準に一致するメンバが複数ある場合にスローされる例外。このクラスは継承できません。

名前空間: System.Reflection
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class
 AmbiguousMatchException
    Inherits SystemException
Dim instance As AmbiguousMatchException
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public sealed class AmbiguousMatchException
 : SystemException
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class AmbiguousMatchException sealed
 : public SystemException
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class AmbiguousMatchException
 extends SystemException
SerializableAttribute 
ComVisibleAttribute(true) 
public final class AmbiguousMatchException
 extends SystemException
解説解説

AmbiguousMatchException は、値 0x8000211D を保持する HRESULT COR_E_AMBIGUOUSMATCH を使用します。

メンバが遅延バインディングで呼び出され、バインディング基準を満たすオーバーロードが複数存在した場合、または、単一の結果のみを返すリフレクション メソッド (System.Type.GetMethod や System.Type.GetProperty など) に渡されたバインディング基準に複数のメンバが一致した場合、AmbiguousMatchException がスローされます。

継承階層継承階層
System.Object
   System.Exception
     System.SystemException
      System.Reflection.AmbiguousMatchException
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

AmbiguousMatchException コンストラクタ ()

空のメッセージ文字列を使用し、主要原因となる例外を null 参照 (Visual Basic では Nothing) に設定して、AmbiguousMatchException クラスの新しいインスタンスを初期化します。

名前空間: System.Reflection
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Dim instance As New AmbiguousMatchException
public AmbiguousMatchException ()
public:
AmbiguousMatchException ()
public AmbiguousMatchException ()
public function AmbiguousMatchException ()
解説解説

AmbiguousMatchException は Exception から継承します。このコンストラクタは、次の表に示すように、Exception オブジェクトのプロパティを設定します。

プロパティ

値

InnerException

null 参照 (Visual Basic では Nothing)

Message

空の文字列 ("")。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

AmbiguousMatchException コンストラクタ (String)

メッセージ文字列セットを特定のメッセージに、主要原因となる例外を null 参照 (Visual Basic では Nothing) に設定して、AmbiguousMatchException クラスの新しいインスタンスを初期化します。

名前空間: System.Reflection
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Dim message As String

Dim instance As New AmbiguousMatchException(message)
public AmbiguousMatchException (
    string message
)
public:
AmbiguousMatchException (
    String^ message
)
public AmbiguousMatchException (
    String message
)
public function AmbiguousMatchException (
    message : String
)

パラメータ

message

この例外がスローされた原因を示す文字列。

解説解説

AmbiguousMatchException は Exception から継承します。このコンストラクタは、次の表に示すように、Exception オブジェクトのプロパティを設定します。

プロパティ

値

InnerException

null 参照 (Visual Basic では Nothing)

Message

message 文字列。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
AmbiguousMatchException クラス
AmbiguousMatchException メンバ
System.Reflection 名前空間

AmbiguousMatchException コンストラクタ


AmbiguousMatchException コンストラクタ (String, Exception)

指定したエラー メッセージと、この例外の原因である内部例外への参照を使用して、AmbiguousMatchException クラスの新しいインスタンスを初期化します。

名前空間: System.Reflection
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説

前の例外の直接の結果としてスローされる例外については、InnerException プロパティに、前の例外への参照が格納されます。InnerException プロパティは、コンストラクタに渡されたものと同じ値を返します。InnerException プロパティによって内部例外値がコンストラクタに渡されなかった場合は、null 参照 (Visual Basic では Nothing) を返します。

AmbiguousMatchException のインスタンスの初期プロパティ値を次の表に示します。

使用例使用例

Mymethod という名前の 2 つのクラスを次の例で示します。一方のクラスは整数をとり、もう一方のクラスは文字列をとります。整数が Mymethod に渡されると、最初のクラスが使用されます。文字列が渡された場合は、2 番目のクラスが使用されます。どちらの Mymethod を使用するか判断できない場合は、AmbiguousMatchException がスローされます。

Class Myambiguous
    
    'The first overload is typed to an Int32
    Overloads Public Shared
 Sub Mymethod(number As Int32)
        Console.Write(ControlChars.Cr + "{0}", "I
 am from Int32 method")
    End Sub 'Mymethod
    
    
    'The second overload is typed to a string
    Overloads Public Shared
 Sub Mymethod(alpha As String)
        Console.Write(ControlChars.Cr + "{0}", "I
 am from a string.")
    End Sub 'Mymethod
    
    
    Public Shared Sub Main()
        Try
            'The following does not cause as exception
            Mymethod(2) ' goes to Mymethod (Int32)
            Mymethod("3") ' goes to Mymethod
 (string)
            Dim Mytype As Type = Type.GetType("Myambiguous")
            
            Dim Mymethodinfo32 As MethodInfo
 = Mytype.GetMethod("Mymethod", New
 Type() {GetType(Int32)})
            Dim Mymethodinfostr As MethodInfo
 = Mytype.GetMethod("Mymethod", New
 Type() {GetType(System.String)})
            
            'Invoke a method, utilizing a Int32 integer
            Mymethodinfo32.Invoke(Nothing, New
 Object() {2})
            
            'Invoke the method utilizing a string
            Mymethodinfostr.Invoke(Nothing, New
 Object() {"1"})
            
            'The following line causes an ambiguious exception
            Dim Mymethodinfo As MethodInfo
 = Mytype.GetMethod("Mymethod")
        ' end of try block
        Catch theException As System.Reflection.AmbiguousMatchException
            Console.Write(ControlChars.Cr & "AmbiguousMatchException
 message - {0}", theException.Message)
        Catch
        End Try
        Return
    End Sub 'Main
End Class 'Myambiguous

'This code 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.
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
 Object[]{2});

            //Invoke the method utilizing a string
            Mymethodinfostr.Invoke(null, new
 Object[]{"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;
    }
}
 
 //This code 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.
ref class Myambiguous
{
public:

   //The first overload is typed to an Int32
   static void Mymethod( Int32 number )
   {
      Console::Write( "\nI am from Int32 method" );
   }

   //The second overload is typed to a String*
   static void Mymethod( String^ alpha )
   {
      Console::Write( "\nI am from a String*." );
   }

   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" );
         array<Type^>^temp0 = {Int32::typeid};
         MethodInfo^ Mymethodinfo32 = Mytype->GetMethod( "Mymethod",
 temp0 );
         array<Type^>^temp1 = {System::String::typeid};
         MethodInfo^ Mymethodinfostr = Mytype->GetMethod( "Mymethod",
 temp1 );

         //Invoke a method, utilizing a Int32 integer
         array<Object^>^temp2 = {2};
         Mymethodinfo32->Invoke( nullptr, temp2 );

         //Invoke the method utilizing a String*
         array<Object^>^temp3 = {"1"};
         Mymethodinfostr->Invoke( nullptr, temp3 );

         //The following line causes an ambiguous exception
         MethodInfo^ Mymethodinfo = Mytype->GetMethod( "Mymethod" );
      }
      catch ( System::Reflection::AmbiguousMatchException^ theException
 ) 
      {
         Console::Write( "\nAmbiguousMatchException message - {0}", theException->Message
 );
      }
      catch ( Exception^ ) 
      {
         Console::Write( "\nError thrown" );
      }

      return;
   }
};

int main()
{
   Myambiguous::main();
}

//This code 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.
class MyAmbiguous
{
    //The first overload is typed to an Int32
    public static void MyMethod(Integer
 number)
    {
        Console.Write("\n{0}", "I am from Int32 method");
    } //MyMethod

    //The second overload is typed to a string
    public static void MyMethod(String
 alpha)
    {
        Console.Write("\n{0}", "I am from a string.");
    } //MyMethod

    public static void main(String[]
 args)
    {
        try {
            //The following does not cause as exception
            MyMethod(new Integer(2)); // goes to
 MyMethod (Int32)
            MyMethod("3"); // goes to MyMethod (string)

            Type myType = Type.GetType("MyAmbiguous");
            MethodInfo myMethodInfo32 = myType.GetMethod("MyMethod", 
                new Type[] { Integer.class.ToType()
 });
            MethodInfo myMethodInfoStr = myType.GetMethod("MyMethod", 
                new Type[] { String.class.ToType()
 });

            //Invoke a method, utilizing a Int32 integer
            myMethodInfo32.Invoke(null, new
 Object[] { new Integer(2) });

            //Invoke the method utilizing a string
            myMethodInfoStr.Invoke(null, new
 Object[] { "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.get_Message());
        }
        catch (System.Exception exp) {
            Console.Write("\nError thrown");
        }
        return;
    } //main
} //MyAmbiguous

//This code 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 プロパティ


AmbiguousMatchException メソッド


AmbiguousMatchException メンバ

メンバへのバインド時に、バインディング基準に一致するメンバが複数ある場合にスローされる例外。このクラスは継承できません。

AmbiguousMatchException データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド AmbiguousMatchException オーバーロードされます。 AmbiguousMatchException クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
参照参照

関連項目

AmbiguousMatchException クラス
System.Reflection 名前空間
Exception
SystemException

その他の技術情報

例外の処理とスロー



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「AmbiguousMatchException」の関連用語

AmbiguousMatchExceptionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



AmbiguousMatchExceptionのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS