{"record":{"id":"32012d22de4a609d","repo":"HandyOrg/HandyControl","slug":"the-jumplist-can-t-be-applied-until-endinit-has-been-called","errorCode":null,"errorMessage":"The JumpList can't be applied until EndInit has been called.","messagePattern":"The JumpList can't be applied until EndInit has been called\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Shared/Microsoft.Windows.Shell/JumpList.cs","lineNumber":167,"sourceCode":"            string result;\n            HRESULT hrLeft = NativeMethods.GetCurrentProcessExplicitAppUserModelID(out result);\n            if (hrLeft == HRESULT.E_FAIL)\n            {\n                hrLeft = HRESULT.S_OK;\n                result = null;\n            }\n            hrLeft.ThrowIfFailed();\n            return result;\n        }\n    }\n\n    [SuppressMessage(\"Microsoft.Naming\", \"CA2204:Literals should be spelled correctly\", MessageId = \"JumpList\")]\n    [SuppressMessage(\"Microsoft.Naming\", \"CA2204:Literals should be spelled correctly\", MessageId = \"EndInit\")]\n    public void Apply()\n    {\n        if (this._initializing == true)\n        {\n            throw new InvalidOperationException(\"The JumpList can't be applied until EndInit has been called.\");\n        }\n        this._initializing = new bool?(false);\n        this._ApplyList();\n    }\n\n    private void ApplyFromApplication()\n    {\n        if (this._initializing != true && !this._IsUnmodified)\n        {\n            this._initializing = new bool?(false);\n        }\n        if (this._application == Application.Current && this._initializing == false)\n        {\n            this._ApplyList();\n        }\n    }\n\n    [SuppressMessage(\"Microsoft.Globalization\", \"CA1303:Do not pass literals as localized parameters\", MessageId = \"Standard.Verify.IsApartmentState(System.Threading.ApartmentState,System.String)\")]","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/Microsoft.Windows.Shell/JumpList.cs#L149-L185","documentation":"JumpList.Apply() throws this InvalidOperationException when the JumpList is still in designer-initialization state (_initializing == true). WPF's ISupportInitialize pattern marks a JumpList as initializing between BeginInit and EndInit; applying the list before initialization completes would apply a partially constructed list.","triggerScenarios":"Calling JumpList.Apply() (or SetJumpList + Apply) after BeginInit() but before EndInit(), or in XAML/data-binding scenarios where the framework is still initializing the object.","commonSituations":"Constructing a JumpList in code and calling Apply immediately after BeginInit; declaring a JumpList in XAML resource sections and invoking Apply from a handler that runs before the end-init pass; incorrect manual use of ISupportInitialize.","solutions":["Call EndInit() on the JumpList before calling Apply()","Remove the explicit BeginInit() call if it is not needed","Defer Apply() until after window/component initialization completes (e.g. Loaded event)","Check the _initializing state / wrap Apply in try-catch InvalidOperationException to detect premature calls"],"exampleFix":"// before\nvar jl = new JumpList();\njl.BeginInit();\njl.Apply(); // throws\n// after\nvar jl = new JumpList();\njl.BeginInit();\njl.EndInit();\njl.Apply();","handlingStrategy":"validation","validationCode":"bool isInitializing = typeof(JumpList).GetProperty(\"IsInitializing\")?.GetValue(jumpList) as bool? ?? false;\nif (isInitializing) jumpList.EndInit();\njumpList.Apply();","typeGuard":"static bool CanApply(JumpList jl) => jl != null; // apply only after BeginInit/EndInit pair completes","tryCatchPattern":"try { jumpList.Apply(); }\ncatch (InvalidOperationException ex) { Log.Warn(\"JumpList applied before EndInit\", ex); }","preventionTips":["Always pair BeginInit with EndInit before Apply","Apply JumpLists from the window's Loaded event, not during construction","Prefer JumpList.SetJumpList + application-level wiring over manual lifecycle calls"],"tags":["wpf","jumplist","initialization","invalid-operation"],"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"}