stride3d/stride · error · InvalidOperationException

This WorkProgressViewModel is already associated to a…

Error message

This WorkProgressViewModel is already associated to a progress window

What it means

NotifyWindowWillOpen marks a WorkProgressViewModel as bound to a progress window. If the method is called when windowWillOpen is already true, the library throws InvalidOperationException because a single view model cannot be associated with more than one window. ShowProgressWindow calls this internally when opening a window for the view model.

Solutions

  1. Create a new WorkProgressViewModel for each progress window instead of reusing an instance.
  2. Ensure the previous window is closed so NotifyWindowClosed resets windowWillOpen before reopening.
  3. Track whether the window is already open and skip ShowProgressWindow if so.
  4. Catch InvalidOperationException to detect double-open attempts and no-op.

Example fix

// before
if (progressViewModel == null)
    progressViewModel = new WorkProgressViewModel(...);
progressViewModel.ShowProgressWindow();
// after
if (progressViewModel == null)
    progressViewModel = new WorkProgressViewModel(...);
else if (progressViewModel.WorkDone)
    progressViewModel = new WorkProgressViewModel(...);
progressViewModel.ShowProgressWindow();
Defensive patterns

Strategy: validation

Validate before calling

if (progressViewModel.IsWindowOpen) return; // skip opening a second window

Try / catch

try { vm.ShowProgressWindow(); }
catch (InvalidOperationException) { /* window already open; reuse it */ }

Prevention

When it happens

Trigger: Calling ShowProgressWindow (or NotifyWindowWillOpen directly) a second time on the same WorkProgressViewModel instance without the previous window having been closed (NotifyWindowClosed called).

Common situations: Launching two progress dialogs for the same long-running view model, e.g. re-showing progress for an already displayed operation, or reusing a cached view model across concurrent editor operations.

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 stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/ff9ed5a2813dd1d5. Report an issue: GitHub.

Appendix: source

Thrown at sources/editor/Stride.Core.Assets.Editor/ViewModel/Progress/WorkProgressViewModel.cs:225

            switch (KeepOpen)
            {
                case KeepOpen.Never:
                    return false;
                case KeepOpen.OnWarningsOrErrors:
                    return Log.HasWarnings || Log.HasErrors;
                case KeepOpen.OnErrors:
                    return Log.HasErrors;
                case KeepOpen.Always:
                    return true;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }

        internal void NotifyWindowWillOpen()
        {
            if (windowWillOpen)
                throw new InvalidOperationException("This WorkProgressViewModel is already associated to a progress window");

            windowWillOpen = true;
        }

        internal void NotifyWindowClosed()
        {
            workProgressClosed.TrySetResult(0);
        }

        /// <summary>
        /// Helper method to raise event.
        /// </summary>
        /// <param name="handler">The event handler to raise.</param>
        private void RaiseEvent(EventHandler<WorkProgressNotificationEventArgs> handler)
        {
            handler?.Invoke(this, new WorkProgressNotificationEventArgs(this));
        }

View on GitHub (pinned to 96fad776d2)