I'm trying to debug some information of my list that is made of objects of a class I made. When I try to check it, it stops debugging and gives the following code in the output window:
The program <6880> 'MyApp.vshost.exe' has exited with code -2147023895 (0x800703e9).
When I searched for the number, I found this:
Recursion too deep; the stack overflowed.
When I read this, it seems to me that I have an infinite loop or something like that.
When I search for this, I get to MSDN and it says contact the supplier. well that's me....
Another topic I found on stackoverflow is this one: Runtime exception, recursion too deep
But this is about looping for like .. a really long time.
Mine is just a list with some information saved in it.
This is the class
class LinePiece
{
private string type;
private string elementNumber;
private int beginX, beginY;
private int endX, endY;
private int diameter;
private string text;
public string Type { get { return type; } }
public string ElementNumber { get { return ElementNumber; } }
public int BeginX { get { return beginX; } }
public int BeginY { get { return beginY; } }
public int EndX { get { return endX; } }
public int EndY { get { return endY; } }
public LinePiece(string a_type, string a_eleNr, int a_beginX, int a_beginY, int a_endX, int a_endY)
{
type = a_type;
elementNumber = a_eleNr;
beginX = a_beginX;
beginY = a_beginY;
endX = a_endX;
endY = a_endY;
}
}
And I create a list like this: List<LinePiece> l_linePieces = new List<LinePiece>();
and add a line like this:
LinePiece LP = new LinePiece(s_lpType, s_EleNr, i_X1, i_Y1, i_X2, i_Y2);
l_linePieces.Add(LP);
When I debug at this point, I click on the l_linePieces
it displays the amount of objects are in it. But when I try to open one of them, it stops and gives the error.
Also when I don't debug it, it's all fine, it gives no errors etc. But I want to check some values in this list.
So how can I solve this issue?
This property getter...
public string ElementNumber { get { return ElementNumber; } }
...calls itself.
To avoid this in future, you should probably use automatic properties, which look like this:
public string ElementNumber { get; set; }
The compiler will invent a hidden backing field.
You can initialise the auto properties in your constructor as follows:
public LinePiece(string a_type, string a_eleNr,
int a_beginX, int a_beginY,
int a_endX, int a_endY)
{
Type = a_type;
ElementNumber = a_eleNr;
BeginX = a_beginX;
BeginY = a_beginY;
EndX = a_endX;
EndY = a_endY;
}
If you want to set them only from the class itself (i.e. in the constructor), then use private set
:
public string ElementNumber { get; private set; }
User contributions licensed under CC BY-SA 3.0