{"record":{"id":"54e494e1627f76a7","repo":"dotnet/wpf","slug":"sr-jumplist-cantnestbegininitcalls","errorCode":null,"errorMessage":"SR.JumpList_CantNestBeginInitCalls","messagePattern":"SR\\.JumpList_CantNestBeginInitCalls","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/JumpList.cs","lineNumber":352,"sourceCode":"                    && !ShowRecentCategory\n                    && !ShowFrequentCategory;\n            }\n        }\n        #region ISupportInitialize Members\n\n        /// <summary>\n        /// Prepare the JumpList for modification.\n        /// </summary>\n        /// <remarks>\n        /// This works in concert with the Application.JumpList attached property.  The JumpList will automatically be applied\n        /// to the current application when attached and a corresponding call to EndInit is made.\n        /// Nested calls to BeginInit are not allowed.\n        /// </remarks>\n        public void BeginInit()\n        {\n            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","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/JumpList.cs#L334-L370","documentation":"JumpList implements ISupportInitialize, and BeginInit marks the list as being initialized. If the JumpList has already been modified (items added or properties changed) before BeginInit is called again, the second call throws InvalidOperationException because nested begin/init cycles are not supported. This guards the two-phase initialization contract that EndInit relies on.","triggerScenarios":"Calling BeginInit() twice on the same JumpList instance without a matching EndInit(); calling BeginInit() after the list was mutated (e.g. JumpItems.Add) from a previous incomplete init cycle (IsUnmodified is false).","commonSituations":"XAML authors nesting JumpList.BeginInit in a template instantiated more than once; code that calls BeginInit defensively each time items are appended; re-initializing a cached JumpList instance after it was already used.","solutions":["Remove the redundant BeginInit() call — one Begin/End pair per JumpList instance is enough.","If items must be batched, add them all between a single BeginInit/EndInit pair instead of re-entering BeginInit.","Create a fresh JumpList instance for each initialization cycle instead of reusing a mutated one.","Call EndInit() (or Apply()) to complete any outstanding cycle before starting a new one."],"exampleFix":"// before\njumpList.BeginInit();\njumpList.JumpItems.Add(new JumpTask { ... });\njumpList.BeginInit(); // throws\n// after\njumpList.BeginInit();\njumpList.JumpItems.Add(new JumpTask { ... });\njumpList.EndInit();","handlingStrategy":"validation","validationCode":"if (jumpList.JumpItems.Count > 0)\n    throw new InvalidOperationException(\"BeginInit requires an unmodified JumpList; use a new instance.\");","typeGuard":"bool CanBeginInit(JumpList jl) => jl != null && jl.JumpItems.Count == 0;","tryCatchPattern":null,"preventionTips":["Call BeginInit exactly once per JumpList instance.","Batch all JumpItems additions between one BeginInit/EndInit pair.","Never reuse a JumpList after EndInit for a new init cycle — create a new one.","Prefer the simple Apply() flow when two-phase init is not needed."],"tags":["wpf","jumplist","initialization","invalid-operation"],"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"}