{"record":{"id":"d6e12c643b89f63c","repo":"dotnet/wpf","slug":"sr-jumplist-cantapplyuntilendinit","errorCode":null,"errorMessage":"SR.JumpList_CantApplyUntilEndInit","messagePattern":"SR\\.JumpList_CantApplyUntilEndInit","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/JumpList.cs","lineNumber":416,"sourceCode":"            {\n                string appId;\n                HRESULT hr = NativeMethods2.GetCurrentProcessExplicitAppUserModelID(out appId);\n                if (hr == HRESULT.E_FAIL)\n                {\n                    // This is how Shell signals that the app id hasn't been set.\n                    hr = HRESULT.S_OK;\n                    appId = null;\n                }\n                hr.ThrowIfFailed();\n                return appId;\n            }\n        }\n\n        public void Apply()\n        {\n            if (_initializing == true)\n            {\n                throw new InvalidOperationException(SR.JumpList_CantApplyUntilEndInit);\n            }\n\n            // After this attempting to use ISupportInitialize is invalid.\n            _initializing = false;\n\n            ApplyList();\n        }\n\n        private void ApplyFromApplication()\n        {\n            // If we're here and the caller has modified the JumpList without using ISupportInitialize\n            // we still want to apply the changes.\n            if (_initializing != true && !IsUnmodified)\n            {\n                _initializing = false;\n            }\n\n            if (_application == Application.Current && _initializing == false)","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/JumpList.cs#L398-L434","documentation":"Apply() pushes the JumpList to the Windows shell. It throws InvalidOperationException if the list is still inside a BeginInit/EndInit cycle (_initializing == true), since the list contents are not final until EndInit. After Apply, ISupportInitialize can no longer be used on the instance.","triggerScenarios":"Calling Apply() between BeginInit() and EndInit(); applying a list that XAML deserialization is still initializing (BeginInit called but EndInit not yet reached).","commonSituations":"Calling Apply at application startup while the JumpList defined in App.xaml is still being parsed; a UI handler firing Apply before an async initialization finished.","solutions":["Move the Apply() call after EndInit() completes.","Trigger Apply only from code that runs after application initialization finished.","Guard with a flag: call Apply once initialization is done.","Do not mix Apply() with the BeginInit/EndInit pattern on the same instance — pick one flow."],"exampleFix":"// before\njumpList.BeginInit();\njumpList.JumpItems.Add(new JumpTask { ... });\njumpList.Apply(); // throws\n// after\njumpList.BeginInit();\njumpList.JumpItems.Add(new JumpTask { ... });\njumpList.EndInit();\njumpList.Apply();","handlingStrategy":"validation","validationCode":"if (!initializationComplete)\n    throw new InvalidOperationException(\"Wait for EndInit before calling JumpList.Apply().\");","typeGuard":null,"tryCatchPattern":"try { jumpList.Apply(); }\ncatch (InvalidOperationException ex) { Log.Warn(\"Apply called before EndInit\", ex); }","preventionTips":["Never call Apply between BeginInit and EndInit.","Trigger Apply from code that runs after XAML/app initialization completes.","Use a readiness flag or completed event before applying.","Pick either ISupportInitialize or Apply, not both interleaved."],"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"}