{"record":{"id":"ae373534eaa7cc0e","repo":"tui-cs/Terminal.Gui","slug":"the-view-is-already-initialized","errorCode":null,"errorMessage":"The view is already initialized.","messagePattern":"The view is already initialized\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/ViewBase/View.cs","lineNumber":266,"sourceCode":"    /// <remarks>\n    ///     <para>\n    ///         Views can opt-in to more sophisticated initialization by implementing overrides to\n    ///         <see cref=\"ISupportInitialize.BeginInit\"/> and <see cref=\"ISupportInitialize.EndInit\"/> which will be called\n    ///         when the <see cref=\"SuperView\"/> is initialized.\n    ///     </para>\n    ///     <para>\n    ///         If first-run-only initialization is preferred, overrides to <see cref=\"ISupportInitializeNotification\"/> can\n    ///         be implemented too, in which case the <see cref=\"ISupportInitialize\"/> methods will only be called if\n    ///         <see cref=\"ISupportInitializeNotification.IsInitialized\"/> is <see langword=\"false\"/>. This allows proper\n    ///         <see cref=\"View\"/> inheritance hierarchies to override base class layout code optimally by doing so only on\n    ///         first run, instead of on every run.\n    ///     </para>\n    /// </remarks>\n    public virtual void BeginInit ()\n    {\n        if (IsInitialized)\n        {\n            throw new InvalidOperationException (\"The view is already initialized.\");\n        }\n#if AUTO_CANFOCUS\n        _oldCanFocus = CanFocus;\n        _oldTabIndex = _tabIndex;\n#endif\n\n        BeginInitAdornments ();\n\n        if (InternalSubViews.Count <= 0)\n        {\n            return;\n        }\n\n        foreach (View view in InternalSubViews)\n        {\n            if (!view.IsInitialized)\n            {\n                view.BeginInit ();","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/ViewBase/View.cs#L248-L284","documentation":"BeginInit is part of the ISupportInitialize lifecycle. It throws if the view is already initialized (IsInitialized == true), preventing double-initialization which would corrupt adornment state, key bindings, and SubView trees. Once EndInit has run, BeginInit must not be called again.","triggerScenarios":"Calling view.BeginInit() twice; calling BeginInit after the application framework already ran the init cycle (app.Run auto-initializes the view tree); manually initializing a view that was already initialized by a parent's EndInit.","commonSituations":"Mixing manual ISupportInitialize calls with app.Run (which initializes the whole tree); reusing a view instance across sessions; custom Runnable that double-initializes.","solutions":["Guard with 'if (!view.IsInitialized)' before calling BeginInit.","Let app.Run handle initialization instead of calling BeginInit/EndInit manually.","Create a fresh View instance for a new session rather than re-initializing an old one."],"exampleFix":"// before\nview.BeginInit();\nview.EndInit();\nview.BeginInit(); // throws\n// after\nif (!view.IsInitialized) view.BeginInit();","handlingStrategy":"validation","validationCode":"if (!view.IsInitialized) view.BeginInit();","typeGuard":"static bool CanBeginInit (View v) => !v.IsInitialized;","tryCatchPattern":null,"preventionTips":["Guard BeginInit with IsInitialized.","Let app.Run drive the init cycle.","Create new View instances per session."],"tags":["lifecycle","begininit","isinitialized","initialization"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}