KB Article B181657
Visible to All Users

Layout - Troubleshooting the "Error creating window handle" or "Infinite recursion detected: the 'XXX' view was created 51 times" errors

SYMPTOMS

There may be different errors for different platforms

Common (16.1+):
Type:       InfiniteRecursionException
Message:    An error with number 1092 has occurred.
Error message: Infinite recursion detected: the 'Product_DetailView' detail view was created 51 times
Data:       0 entries
Stack trace:
   at DevExpress.ExpressApp.CompositeView.ProcessModelView(IModelDetailView detailView, Dictionary`2 viewsCounter)
   at DevExpress.ExpressApp.CompositeView.CheckModelRecursive(IModelCompositeView model, Dictionary`2 viewsCounter)

WinForms (older versions):
     Type: Win32Exception
     Message: Error creating window handle.
     Data: 0 entries
     Stack trace:
   at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
   at System.Windows.Forms.Control.CreateHandle()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.ControlCollection.Add(Control value)
   at DevExpress.ExpressApp.Win.Templates.ViewSiteManager.FillViewSite(View view) in S:\2010.2\XAF\DevExpress.ExpressApp.Win\Templates\ViewSiteManager.cs:line 67
   at DevExpress.ExpressApp.Win.Templates.ViewSiteManager.view_ControlsCreated(Object sender, EventArgs e) in S:\2010.2\XAF\DevExpress.ExpressApp.Win\Templates\ViewSiteManager.cs:line 40
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at DevExpress.ExpressApp.View.OnControlsCreated() in S:\2010.2\XAF\DevExpress.ExpressApp\View.cs:line 141
   at DevExpress.ExpressApp.View.CreateControls() in S:\2010.2\XAF\DevExpress.ExpressApp\View.cs:line 279
   at DevExpress.ExpressApp.Win.Templates.ViewSiteManager.FillViewSite(View view) in S:\2010.2\XAF\DevExpress.ExpressApp.Win\Templates\ViewSiteManager.cs:line 49
   at DevExpress.ExpressApp.Win.Templates.ViewSiteManager.viewSite_HandleCreated(Object sender, EventArgs e) in S:\2010.2\XAF\DevExpress.ExpressApp.Win\Templates\ViewSiteManager.cs:line 36
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnHandleCreated(EventArgs e)
   at DevExpress.XtraEditors.XtraScrollableControl.OnHandleCreated(EventArgs e)
   at DevExpress.XtraEditors.PanelControl.OnHandleCreated(EventArgs e)
   at System.Windows.Forms.Control.WmCreate(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at DevExpress.XtraEditors.XtraScrollableControl.WndProc(Message& m)
   at DevExpress.Utils.Controls.PanelBase.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
     InnerException is null

ASP.NET (older versions):
  DevExpress.ExpressApp.Web.Controls.ViewSiteControl.SetView
  DevExpress.ExpressApp.Web.Controls.ViewDependentControl<System.Web.UI.WebControls.Panel>.OnInit
  [External Code]
  DevExpress.ExpressApp.Web.Controls.ViewSiteControl.SetView
  DevExpress.ExpressApp.Web.Controls.ViewDependentControl<System.Web.UI.WebControls.Panel>.OnInit
  [External Code]
  DevExpress.ExpressApp.Web.WebWindowTemplateHttpHandler.ProcessRequest
  [External Code]

TYPICAL SCENARIOS
1.  When MasterDeailMode = ListViewAndDetailView for a nested ListView whose element type is the same as for the master object.
It is possible to achieve this by setting the DefaultListViewMasterDetailMode property at the BOModel | Class level or the MasterDetailMode property at the Views | Master_Details_ListView level.
Consider the following code that leads to this invalid situation:

C#
[DefaultListViewOptions(DevExpress.ExpressApp.MasterDetailMode.ListViewAndDetailView)] public class Product : BaseObject { [Association("Product-Product"), DevExpress.Xpo.Aggregated] public XPCollection<Product> NestedProducts { get { return GetCollection<Product>("NestedProducts"); } }

2.   When a DetailView contains DetailPropertyEditor pointing to a reference property whose type is the same as for the master object or the embedded DetailView to which it points contains the same DetailPropertyEditor.
Consider the following code that leads to this invalid situation:

C#
public class Product : BaseObject { [DevExpress.Xpo.Aggregated, EditorAlias(EditorAliases.DetailPropertyEditor)] [ExpandObjectMembers(ExpandObjectMembers.Never)] public Product ParentProduct2 { get { return ParentProduct; } }

3.   You have insufficient memory on your machine or too many opened window applications. Refer to the http://stackoverflow.com/questions/222649/winforms-issue-error-creating-window-handle thread for more details and possible solutions, because they are not specific to DevExpress.

CAUSE
In scenarios #1-2, this error occurs due to the expected recursion in UI element creation caused by the ListViewAndDetailView setting applied to the nested ListView when a master class has a detail collection of objects of the same type. Such a layout cannot be physically built, because the same nested ListView in the master DetailView is created again and again until the number of window handles reaches the operating system limits. This behavior is not specific to a ListEditor type (e.g., TreeListEditor, GridListEditor, etc.).

RESOLUTION
The only feasible solution here is to avoid this problematic UI settings combination at all. There are many different ways to do this starting from changing the View/PropertyEditor options and finishing by removing problematic UI elements from the form completely.
For instance, consider the following options for the aforementioned scenarios #1-2:
    1.1. Do not set MasterDetailView = ListViewAndDetailView for the nested Master_Details_ListView.
    1.2. Instead of setting the DefaultListViewMasterDetailMode property for the whole class, set MasterDetailMode = ListViewAndDetailView for the root ListView only.
    2.1. Specify a different DetailView node without the same DetailPropertyEditor via the DevExpress.ExpressApp.Model > IModelMemberViewItem > View attribute in the Model Editor.
    2.2. Hide the problematic editor from the layout via the designer or code attributes.
What is best for each particular case in each client application is fully up to the end developer. Our framework can just warn developers about such situations only during the application run (it is almost impossible to detect the view creation recursion statically, because controls are created only at the moment they become visible to end-users). Starting with v16.1, there will be InfiniteRecursionException from XAF when such an error configuration is detected at runtime. After that, you, as a developer can act and do what is best for your particular case.

Comments (2)
W W
Willem de Vries 5 years ago

    Starting with v16.1, there will be InfiniteRecursionException from XAF when such an error configuration is detected at runtime.

    Please prohibit saving the layout when this error occurs.

    Dennis Garavsky (DevExpress) 5 years ago

      @Willem de Vries: I've answered you in a separate ticket (T885047: Questions on InfiniteRecursionException (B181657)).

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.