An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll in c#
-
Hi I have classes property and sketch in htis property will be linked to skecth class and foure different classes which r linked to the skecth class and two generic list one is for skecth and other is for data of type Object when i run the program i iam grtting the error here public Sketch FirstData() { // return Datas[Datas.Count]; foreach (Object data in Datas) { if (data is Door) { Door door = (Door)data; } if (data is Fixture) { Fixture fixture = (Fixture)data; } if (data is Wall) { Wall wall = (Wall)data; } if (data is Window) { Window window = (Window)data; } //return } return getSketch(1); } private Sketch getSketch(Int32 id) { foreach (Object data in Datas) { if (data is Door) { Door door = (Door)data; door.Id = id; } if (data is Fixture) { Fixture fixture = (Fixture)data; fixture.Id = id; } if (data is Wall) { Wall wall = (Wall)data; wall.Id = id; } if (data is Window) { Window window = (Window)data; window.Id = id; } } return getSketch(id); } An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll how can i slove this problem? can any one help me in this
-
Hi I have classes property and sketch in htis property will be linked to skecth class and foure different classes which r linked to the skecth class and two generic list one is for skecth and other is for data of type Object when i run the program i iam grtting the error here public Sketch FirstData() { // return Datas[Datas.Count]; foreach (Object data in Datas) { if (data is Door) { Door door = (Door)data; } if (data is Fixture) { Fixture fixture = (Fixture)data; } if (data is Wall) { Wall wall = (Wall)data; } if (data is Window) { Window window = (Window)data; } //return } return getSketch(1); } private Sketch getSketch(Int32 id) { foreach (Object data in Datas) { if (data is Door) { Door door = (Door)data; door.Id = id; } if (data is Fixture) { Fixture fixture = (Fixture)data; fixture.Id = id; } if (data is Wall) { Wall wall = (Wall)data; wall.Id = id; } if (data is Window) { Window window = (Window)data; window.Id = id; } } return getSketch(id); } An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll how can i slove this problem? can any one help me in this
Hello, The problem is that you call "getSketch(id)" recursive! "return getSketch(id);" You will never come out of this method. I'm not sure what this program should do, but I have the feeling that the "getSketch" method should somewhere instanciate a "Sketch" object and return this one. Apart from that you should really work with interfaces, as you have to check four types and write at the same param. Hope it helps!
All the best, Martin