Runtime Error 4008... Layout Cycle Detected... Layout Could Not Complete.
-
Hello All, I have came across below mentioned error message. I dont know why such types issue happens.Anyone can tell me why this issue happens... Runtime Error 4008... Layout Cycle Detected... Layout Could Not Complete. Thanks
This means that you have put too many user controls on the page for the render cycle to complete. It has been upper bounded so that "pathological" (thanks to Microsoft's Rob Relyea for using this term) bounds don't come into play. Basically, the layout has been bounded so that the layout cycle doesn't complete because the layout size is changing. Rob Relyea has this to say (citing textboxes as an example): "Layout uses while loops, and the loops need some sort of upper bound on them so that they don’t loop forever in pathological conditions. An example of a pathological condition is if foo’s size is changed in the foo.SizeChanged event handler. There are a number of ways that a layout loop counter can be “used up” legitimately, such as doing anything to invalidate measure during an arrange call, invalidating measure or arrange during a SizeChanged or LayoutUpdated handler (even if a pathological condition is avoided), etc. The TextBox control is doing something to “use up” a layout loop iteration. Since the layout cycle detection is triggered at 250 iterations, under ideal circumstances, you can measure/arrange at most ~250 TextBoxes at once. It has nothing to do with frame rate, the hardware, the browser, etc. It also doesn’t matter how many TextBoxes you have in total, just how many you are laying out in one frame. This is most critical at startup time, when if you have > 250 visible TextBoxes in the tree, you will get a layout cycle. You will also have problems any other time you add > 250 visible TextBoxes, or if you have somehow incrementally added TextBoxes in groups so that you have gotten away with having more than 250, but all TextBoxes layout has been invalidated at once, such as by resizing the browser. You can have as many collapsed TextBoxes on the screen as you want—layout just skips over collapsed controls. Also, if you add the TextBoxes incrementally, and somehow manage them so that they won’t all get invalidated at once (e.g. by putting them in parent containers that won’t ever be resized) you should be OK."
Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility