Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reflection.TargetInvocationException

I have a class named carroms. When I create its object, there is no error. But when I create an array of carroms then, this exception is thrown:

An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in PresentationFramework.dll

Additional information: Exception has been thrown by the target of an invocation.

My code for the carroms class:

class carroms
{

    private bool player;

    public bool checkPlayer
    {
        get { return player; }
        set { player = value; }
    }

    private Point center;

    public Point carromCenter
    {
        get { return center; }
        set { center = value; }
    }

    private Point[] points;

    public Point[] carromPoints
    {
        get { return points; }
        set { points = value; }
    }

    private double width;

    public double carromWidth
    {
        get { return width; }
        set { width = value;
        }
    }

    private double height;

    public double carromHeight
    {
        get { return height; }
        set { height = value; }
    }

    public carroms()
    {
        points = new Point[370];
    }

    public Ellipse draw()
    {
        Ellipse myellipse = new Ellipse();
        myellipse.Height = carromHeight;
        myellipse.Width = carromWidth;
        if (checkPlayer == true)
        {
            myellipse.Fill = Brushes.Black;
        }
        else
        {
            myellipse.Fill = Brushes.Beige;
        }
        return myellipse;
    }
}

And my code for creating the object:

Random randi = new Random();
carroms[] mycarroms = new carroms[5];
mycarroms[0].carromHeight = 100;
mycarroms[0].carromWidth = 100;
mycanvas.Children.Add(mycarroms[0].draw());
like image 527
Affuu Avatar asked Dec 14 '13 07:12

Affuu


People also ask

What is system reflection TargetInvocationException?

System. Reflection. TargetInvocationException Class Represents the error that occurs when a method invoked via reflection throws an exception.

What does TargetInvocationException mean?

TargetInvocationException uses the HRESULT COR_E_TARGETINVOCATION which has the value 0x80131604. When created, the TargetInvocationException is passed a reference to the exception thrown by the method invoked through reflection. The InnerException property holds the underlying exception.

What is Target Invocation exception?

The InvocationTargetException is a checked exception that holds an exception thrown by an invoked method or constructor. Since JDK 1.4, this exception has been retrofitted to conform to the general-purpose exception-chaining mechanism.


1 Answers

Want to add something, Don't get intimidated with TargetInvocationException as it does not serve too much of information. You should See Inner Exception to get the root cause. InnerException could be of type AggregateException, in that case you need to go further down to get all the exception details.

like image 150
crypted Avatar answered Sep 19 '22 12:09

crypted