{"record":{"id":"958a606a2c73efea","repo":"dotnet/wpf","slug":"sr-jumplist-cantcallunbalancedendinit","errorCode":null,"errorMessage":"SR.JumpList_CantCallUnbalancedEndInit","messagePattern":"SR\\.JumpList_CantCallUnbalancedEndInit","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/JumpList.cs","lineNumber":368,"sourceCode":"            if (!IsUnmodified)\n            {\n                throw new InvalidOperationException(SR.JumpList_CantNestBeginInitCalls);\n            }\n\n            _initializing = true;\n        }\n\n        /// <summary>\n        /// Signal the end of initialization of this JumpList.  If it is attached to the current Application, apply the contents of the jump list.\n        /// </summary>\n        /// <remarks>\n        /// Calls to EndInit must be paired with calls to BeginInit.\n        /// </remarks>\n        public void EndInit()\n        {\n            if (_initializing != true)\n            {\n                throw new NotSupportedException(SR.JumpList_CantCallUnbalancedEndInit);\n            }\n\n            _initializing = false;\n\n            // EndInit only implicitly applies the list if the current Application has been set as an attached property.\n            ApplyFromApplication();\n        }\n\n        #endregion\n\n        /// <summary>\n        /// Get the AppUserModelId for the running process.\n        /// </summary>\n        /// <remarks>\n        /// This is a Shell property that currently is only used as part of a heuristic\n        /// for what taskbar item an HWND should be associated with, e.g. you can put\n        /// windows from multiple processes into the same group, or you can prevent glomming\n        /// of HWNDs that would otherwise be shown together.","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/JumpList.cs#L350-L386","documentation":"JumpList uses the ISupportInitialize two-phase pattern: EndInit commits (and optionally auto-applies) the list. EndInit throws NotSupportedException when there is no matching BeginInit in progress (_initializing != true), because committing an uninitialized list breaks the protocol.","triggerScenarios":"Calling EndInit() on a JumpList that never had BeginInit() called, or after EndInit()/Apply() already completed the cycle.","commonSituations":"Cleanup code that calls EndInit in a finally block even when BeginInit threw; copying init code from a class that does not require BeginInit; calling EndInit twice.","solutions":["Ensure every EndInit() is paired with exactly one prior BeginInit() on the same instance.","Wrap BeginInit/EndInit in try/finally only when BeginInit succeeded; otherwise skip EndInit.","Track initialization state yourself with a flag before calling EndInit.","Use Apply() alone if you do not need two-phase initialization."],"exampleFix":"// before\njumpList.EndInit(); // no BeginInit was called -> NotSupportedException\n// after\njumpList.BeginInit();\njumpList.JumpItems.Add(new JumpTask { ... });\njumpList.EndInit();","handlingStrategy":"validation","validationCode":"bool inInit = false;\nvoid SafeEndInit(JumpList jl)\n{\n    if (!inInit) throw new InvalidOperationException(\"EndInit without BeginInit\");\n    jl.EndInit();\n    inInit = false;\n}","typeGuard":null,"tryCatchPattern":"try { jumpList.EndInit(); }\ncatch (NotSupportedException ex) { Log.Warn(\"Unbalanced EndInit on JumpList\", ex); }","preventionTips":["Always pair BeginInit/EndInit in the same scope.","Do not call EndInit in a finally block unless BeginInit succeeded.","Track initialization state with a boolean wrapper.","Consider using Apply() instead of the ISupportInitialize pattern."],"tags":["wpf","jumplist","initialization","not-supported"],"backgroundTag":"invalid-state-transition","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}