{"record":{"id":"eb9eb10160dbd435","repo":"HandyOrg/HandyControl","slug":"calls-to-begininit-cannot-be-nested","errorCode":null,"errorMessage":"Calls to BeginInit cannot be nested.","messagePattern":"Calls to BeginInit cannot be nested\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Shared/Microsoft.Windows.Shell/JumpList.cs","lineNumber":128,"sourceCode":"        {\n            return this._jumpItems;\n        }\n    }\n\n    private bool _IsUnmodified\n    {\n        get\n        {\n            return this._initializing == null && this.JumpItems.Count == 0 && !this.ShowRecentCategory && !this.ShowFrequentCategory;\n        }\n    }\n\n    [SuppressMessage(\"Microsoft.Naming\", \"CA2204:Literals should be spelled correctly\", MessageId = \"BeginInit\")]\n    public void BeginInit()\n    {\n        if (!this._IsUnmodified)\n        {\n            throw new InvalidOperationException(\"Calls to BeginInit cannot be nested.\");\n        }\n        this._initializing = new bool?(true);\n    }\n\n    [SuppressMessage(\"Microsoft.Naming\", \"CA2204:Literals should be spelled correctly\", MessageId = \"EndInit\")]\n    [SuppressMessage(\"Microsoft.Naming\", \"CA2204:Literals should be spelled correctly\", MessageId = \"BeginInit\")]\n    public void EndInit()\n    {\n        if (this._initializing != true)\n        {\n            throw new NotSupportedException(\"Can't call EndInit without first calling BeginInit.\");\n        }\n        this._initializing = new bool?(false);\n        this.ApplyFromApplication();\n    }\n\n    private static string _RuntimeId\n    {","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/Microsoft.Windows.Shell/JumpList.cs#L110-L146","documentation":"JumpList.BeginInit implements ISupportInitialize and may only be called when the JumpList is still in its unmodified state (_IsUnmodified). Calling BeginInit after the list has been changed — effectively nesting or re-initializing initialization — throws InvalidOperationException \"Calls to BeginInit cannot be nested.\"","triggerScenarios":"Calling BeginInit() twice without an intervening EndInit(); calling BeginInit() after adding JumpTasks/JumpPaths or otherwise mutating the JumpList; XAML + code both initializing the same JumpList instance.","commonSituations":"Re-applying a jump list on shutdown after it was already initialized; component designer/initialization frameworks invoking ISupportInitialize twice; manual BeginInit around code that itself triggers initialization.","solutions":["Ensure every BeginInit is matched by exactly one EndInit before calling BeginInit again.","Do not call BeginInit after mutating the list — mutate inside the BeginInit/EndInit pair, or create a fresh JumpList instance instead.","Guard with a flag: only call BeginInit if you did not already initialize this instance.","If re-initialization is needed, construct a new JumpList, populate it, and call SetJumpList + Apply again."],"exampleFix":"// before\njumpList.BeginInit();\njumpList.JumpItems.Add(task);\njumpList.BeginInit(); // throws: nested\n\n// after\njumpList.BeginInit();\njumpList.JumpItems.Add(task);\njumpList.EndInit(); // complete the cycle before any further init","handlingStrategy":"validation","validationCode":"if (_initStarted) return; // BeginInit already in progress or list already modified\njumpList.BeginInit();","typeGuard":null,"tryCatchPattern":"try { jumpList.BeginInit(); /* populate */ jumpList.EndInit(); }\ncatch (InvalidOperationException ex) { Log.Error(ex.Message); }","preventionTips":["Call BeginInit/EndInit exactly once per JumpList instance.","Populate JumpItems only inside the BeginInit/EndInit pair.","Never reuse a JumpList instance after it has been applied; create a new one for re-application.","Avoid mixing XAML-driven and code-driven initialization on the same instance."],"tags":["invalid-operation","jump-list","initialization","lifecycle","wpf"],"backgroundTag":"invalid-state-transition","analyzedSha":"2c0875ebd67326e0c67282967e3e809c69282fee","analyzedAt":"2026-09-14T14:45:29.754Z","contentChangedAt":"2026-09-14T14:45:29.754Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}