{"record":{"id":"858f514dcd8adbec","repo":"AvaloniaUI/Avalonia","slug":"begininit-was-not-called","errorCode":null,"errorMessage":"BeginInit was not called.","messagePattern":"BeginInit was not called\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/StyledElement.cs","lineNumber":359,"sourceCode":"\n        /// <inheritdoc/>\n        IStyleHost? IStyleHost.StylingParent => (IStyleHost?)InheritanceParent;\n\n        internal static ControlTheme InvalidTheme\n            => s_invalidTheme ??= new();\n\n        /// <inheritdoc/>\n        public virtual void BeginInit()\n        {\n            ++_initCount;\n        }\n\n        /// <inheritdoc/>\n        public virtual void EndInit()\n        {\n            if (_initCount == 0)\n            {\n                throw new InvalidOperationException(\"BeginInit was not called.\");\n            }\n\n            if (--_initCount == 0 && _logicalRoot is not null)\n            {\n                ApplyStyling();\n                InitializeIfNeeded();\n            }\n        }\n\n        /// <summary>\n        /// Applies styling to the control if the control is initialized and styling is not\n        /// already applied.\n        /// </summary>\n        /// <remarks>\n        /// The styling system will automatically apply styling when required, so it should not\n        /// usually be necessary to call this method manually.\n        /// </remarks>\n        /// <returns>","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/StyledElement.cs#L341-L377","documentation":"Error \"BeginInit was not called.\" thrown in AvaloniaUI/Avalonia.","triggerScenarios":"Raised when EndInit is called without a preceding BeginInit on a StyledElement. Defend by always pairing BeginInit/EndInit calls (typically via the initialization pattern in XAML loaders) and never calling EndInit directly.","commonSituations":"See trigger scenarios.","solutions":["Call BeginInit() before setting properties on the element and EndInit() afterwards.","Remove the EndInit() call if initialization was never started."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}