dotnet/wpf · error · InvalidOperationException

SR.JumpList_CantApplyUntilEndInit

Error message

SR.JumpList_CantApplyUntilEndInit

What it means

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.

Solutions

  1. Move the Apply() call after EndInit() completes.
  2. Trigger Apply only from code that runs after application initialization finished.
  3. Guard with a flag: call Apply once initialization is done.
  4. Do not mix Apply() with the BeginInit/EndInit pattern on the same instance — pick one flow.

Example fix

// before
jumpList.BeginInit();
jumpList.JumpItems.Add(new JumpTask { ... });
jumpList.Apply(); // throws
// after
jumpList.BeginInit();
jumpList.JumpItems.Add(new JumpTask { ... });
jumpList.EndInit();
jumpList.Apply();
Defensive patterns

Strategy: validation

Validate before calling

if (!initializationComplete)
    throw new InvalidOperationException("Wait for EndInit before calling JumpList.Apply().");

Try / catch

try { jumpList.Apply(); }
catch (InvalidOperationException ex) { Log.Warn("Apply called before EndInit", ex); }

Prevention

When it happens

Trigger: Calling Apply() between BeginInit() and EndInit(); applying a list that XAML deserialization is still initializing (BeginInit called but EndInit not yet reached).

Common situations: 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.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/d6e12c643b89f63c. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/JumpList.cs:416

            {
                string appId;
                HRESULT hr = NativeMethods2.GetCurrentProcessExplicitAppUserModelID(out appId);
                if (hr == HRESULT.E_FAIL)
                {
                    // This is how Shell signals that the app id hasn't been set.
                    hr = HRESULT.S_OK;
                    appId = null;
                }
                hr.ThrowIfFailed();
                return appId;
            }
        }

        public void Apply()
        {
            if (_initializing == true)
            {
                throw new InvalidOperationException(SR.JumpList_CantApplyUntilEndInit);
            }

            // After this attempting to use ISupportInitialize is invalid.
            _initializing = false;

            ApplyList();
        }

        private void ApplyFromApplication()
        {
            // If we're here and the caller has modified the JumpList without using ISupportInitialize
            // we still want to apply the changes.
            if (_initializing != true && !IsUnmodified)
            {
                _initializing = false;
            }

            if (_application == Application.Current && _initializing == false)

View on GitHub (pinned to 81131a70a4)