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());
System. Reflection. TargetInvocationException Class Represents the error that occurs when a method invoked via reflection throws an exception.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With