{"record":{"id":"97c8076282b63874","repo":"tui-cs/Terminal.Gui","slug":"computedlayout-for-superview-to-reference","errorCode":null,"errorMessage":"ComputedLayout for \"{superView}\": \"{to}\" references a SubView (\"{from}\").","messagePattern":"ComputedLayout for \"(.+?)\": \"(.+?)\" references a SubView \\(\"(.+?)\"\\)\\.","errorType":"exception","errorClass":"LayoutException","httpStatus":null,"severity":"critical","filePath":"Terminal.Gui/ViewBase/View.Layout.cs","lineNumber":1253,"sourceCode":"                if (result.Find (v => v == from) is null)\n                {\n                    result.Add (from);\n                }\n\n                // if 'to' is not yet added to the result, add it\n                if (result.Find (v => v == to) is null)\n                {\n                    result.Add (to);\n                }\n\n                // remove from edge\n                edges.Remove ((from, to));\n            }\n            else if (from != superView?.GetTopSuperView (to, from) && !ReferenceEquals (from, to))\n            {\n                if (ReferenceEquals (from.SuperView, to))\n                {\n                    throw new LayoutException ($\"ComputedLayout for \\\"{superView}\\\": \\\"{to}\\\" \" + $\"references a SubView (\\\"{from}\\\").\");\n                }\n\n                throw new LayoutException ($\"ComputedLayout for \\\"{superView}\\\": \\\"{from}\\\" \"\n                                           + $\"linked with \\\"{to}\\\" was not found. Did you forget to add it to {superView}?\");\n            }\n        }\n\n        // return L (a topologically sorted order)\n        return result;\n    } // TopologicalSort\n\n    #endregion Topological Sort\n\n    #region Utilities\n\n    /// <summary>\n    ///     Gets the size of the SuperView's content (nominally the same as\n    ///     the SuperView's <see cref=\"GetContentSize ()\"/>) or the screen size if there's no SuperView.","sourceCodeStart":1235,"sourceCodeEnd":1271,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/ViewBase/View.Layout.cs#L1235-L1271","documentation":"During layout, the topological sort that orders views detected that a view's Pos/Dim (e.g. Pos.Right(otherView)) references a view that is a SubView of the referencing view — a circular/parent-to-child dependency. Layout cannot resolve a parent's position based on its own child's geometry.","triggerScenarios":"A parent view sets its X/Y/Width/Height to a PosView/DimView that points at one of its own SubViews (e.g. parent.X = Pos.Right(child)).","commonSituations":"Programmatically building a container and accidentally referencing a child for the container's position; copy-pasting layout code from a sibling view into its parent.","solutions":["Reverse the dependency: have the child reference the parent (child.X = Pos.Right(parent)), not vice versa.","Use Pos.Absolute or Pos.Center for the parent and let children anchor to it.","Review the from/to views named in the exception message to find the inverted reference."],"exampleFix":"// before\nparent.X = Pos.Left(parentChild);\n// after\nparent.X = Pos.Absolute(2);\nparentChild.X = Pos.Right(parent);","handlingStrategy":"validation","validationCode":"// Ensure the referenced view is NOT a SubView of the referencing view before assigning relative Pos/Dim.\nif (ReferenceEquals (referenced.SuperView, referencer))\n    throw new InvalidOperationException(\"parent must not reference its own child for position\");\nreferencer.X = Pos.Right(referenced);","typeGuard":"static bool IsValidRelativeReference (View referencer, View referenced) =>\n    !ReferenceEquals (referenced.SuperView, referencer);","tryCatchPattern":null,"preventionTips":["Never set a parent's Pos/Dim to reference its own child.","Keep dependencies flowing child -> parent.","Inspect from/to in the exception to find the inversion."],"tags":["layout","topological-sort","circular-dependency","pos"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}