{"record":{"id":"d6ab601b2d2b5448","repo":"tui-cs/Terminal.Gui","slug":"x-cannot-be-null","errorCode":null,"errorMessage":"X cannot be null","messagePattern":"X cannot be null","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/ViewBase/View.Layout.cs","lineNumber":288,"sourceCode":"    ///         resulting in the\n    ///         view being laid out and redrawn as appropriate in the next iteration.\n    ///     </para>\n    ///     <para>\n    ///         Changing this property will cause <see cref=\"Frame\"/> to be updated.\n    ///     </para>\n    ///     <para>The default value is <c>Pos.Absolute (0)</c>.</para>\n    /// </remarks>\n    public Pos X\n    {\n        get => _x;\n        set\n        {\n            if (Equals (_x, value))\n            {\n                return;\n            }\n\n            _x = value ?? throw new ArgumentNullException (nameof (value), @$\"{nameof (X)} cannot be null\");\n\n            PosDimSet ();\n\n            NeedsClearScreenNextIteration ();\n        }\n    }\n\n    private Pos _y = Pos.Absolute (0);\n\n    /// <summary>\n    ///     Gets or sets the declarative vertical position for the view.\n    /// </summary>\n    /// <value>The <see cref=\"Pos\"/> object representing the Y position.</value>\n    /// <remarks>\n    ///     <para>\n    ///         See the View Layout Deep Dive for more information:\n    ///         <see href=\"https://tui-cs.github.io/Terminal.Gui/docs/layout.html\"/>\n    ///     </para>","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/ViewBase/View.Layout.cs#L270-L306","documentation":"The X property (horizontal position) must be a non-null Pos object. Terminal.Gui's layout system is fully declarative — even 'no position' is expressed as Pos.Absolute(0), never as null. A null Pos would leave the layout engine unable to compute a coordinate.","triggerScenarios":"Assigning view.X = null; or a Pos-typed variable that is null (e.g. a field never initialized, or a result of a method that returned null).","commonSituations":"Nullable Pos returned from a helper that returns null on edge cases; conditional initialization that leaves X unset; deserialization gap.","solutions":["Use Pos.Absolute(n) for fixed positions.","Use Pos.Center(), Pos.Percent(n), or Pos.Left(otherView) for relative layout.","If conditionally clearing, set Pos.Absolute(0) rather than null."],"exampleFix":"// before\nview.X = maybePos;\n// after\nview.X = maybePos ?? Pos.Absolute(0);","handlingStrategy":"validation","validationCode":"view.X = pos ?? throw new ArgumentNullException(nameof(pos));\n// or: view.X = pos ?? Pos.Absolute(0);","typeGuard":"static bool IsValidPos (Pos? p) => p is not null;","tryCatchPattern":null,"preventionTips":["Always provide a concrete Pos (Absolute, Center, Percent, View).","Use Pos.Absolute(0) as the neutral default.","Check helper return values for null."],"tags":["layout","pos","x","validation"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}