Description





Description

This exception is thrown by types in the Reflection Library when attempting to dynamically invoke members.

Example

using System;

using System.Reflection;



/// <summary>

/// Shows why a TargetParameterCountException is raised

/// and how to handle it

/// </summary>



public class TargetParameterCountExceptionSample

{

    public static void Main()

    {

        try

        {

            Type type = typeof(string);

            string str = "do unto others..";

            MethodInfo RemoveMethod = type.GetMethod("Remove",

                BindingFlags.Public | BindingFlags.Instance, null,

                new Type[] { typeof(int), typeof(int) }, null);

            string result = (string)RemoveMethod.Invoke(str,

                new object[] { 7, 6, 5 });

            Console.WriteLine(result);

        }

        catch (TargetParameterCountException e)

        {

            Console.WriteLine("Caught exception: {0} - '{1}'",

                e.GetType().Name, e.Message);

        }

        Console.WriteLine();

        Console.WriteLine();

        Console.WriteLine("Press Enter to continue");

        Console.ReadLine();

    }

}


The output is


Caught exception: TargetParameterCountException - 'Parameter count mismatch.'





Press Enter to continue



     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows