stride3d/stride · error · InvalidOperationException

This window has already been shown as blocking.

Error message

This window has already been shown as blocking.

What it means

ShowBlockingWindow tracks every blocking (modal) window in BlockingWindowsList. Showing the same window again while it is already registered as blocking is rejected with InvalidOperationException, since a modal window cannot be shown modally twice.

Solutions

  1. Guard the call: only call ShowBlockingWindow if the window is not already shown (track with a bool or window.IsEnabled/visibility check)
  2. Disable the trigger (button/command) while the blocking window is open
  3. Create a new Window instance for each modal presentation instead of reusing one
  4. Wrap in try/catch on InvalidOperationException as a last resort if re-entrancy is unavoidable

Example fix

// before
private void OnClick(object s, RoutedEventArgs e) => windowManager.ShowBlockingWindow(myDialog);
// after
private void OnClick(object s, RoutedEventArgs e)
{
    if (myDialog.IsVisible) return;
    windowManager.ShowBlockingWindow(myDialog);
}
Defensive patterns

Strategy: validation

Validate before calling

if (!myDialog.IsVisible && !isBlockingShown) windowManager.ShowBlockingWindow(myDialog);

Try / catch

try { windowManager.ShowBlockingWindow(dialog); } catch (InvalidOperationException) { /* dialog already blocking; ignore or focus it */ }

Prevention

When it happens

Trigger: Calling ShowBlockingWindow on a Window instance that is already in the blocking list — e.g. double-click triggering a second ShowDialog, or re-showing a dialog that was never closed/removed.

Common situations: Double-invocation from a button click handler; re-entrant command execution while a modal dialog is open; retaining a Window instance and re-showing it after it was already shown modally.

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/0e7d62a55fb71cc6. Report an issue: GitHub.

Appendix: source

Thrown at sources/presentation/Stride.Core.Presentation.Wpf/Windows/WindowManager.cs:127

            AllWindowsList.Add(MainWindow);

            window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            window.Show();
        }

        /// <summary>
        /// Shows the given window as blocking window. A blocking window will always block the main window of the application, even if shown before it, but does not
        /// affect modal windows. However it can still be blocked by them..
        /// </summary>
        /// <param name="window">The blocking window to show.</param>
        public static void ShowBlockingWindow([NotNull] Window window)
        {
            if (window == null) throw new ArgumentNullException(nameof(window));
            CheckDispatcher();

            var windowInfo = new WindowInfo(window) { IsBlocking = true };
            if (BlockingWindowsList.Contains(windowInfo))
                throw new InvalidOperationException("This window has already been shown as blocking.");

            window.Owner = MainWindow?.Window;
            window.WindowStartupLocation = MainWindow != null ? WindowStartupLocation.CenterOwner : WindowStartupLocation.CenterScreen;

            AllWindowsList.Add(windowInfo);
            BlockingWindowsList.Add(windowInfo);

            // Disable the main window now so the blocking window is recognized as modal when shown.
            RefreshDisabledStates();

            // Update the hwnd on load in case the window is closed before being shown
            // We will receive EVENT_OBJECT_HIDE but not EVENT_OBJECT_SHOW in this case.
            window.Loaded += (sender, e) => windowInfo.ForceUpdateHwnd();
            window.Closed += (sender, e) => ActivateMainWindow();

            Logger.Info($"Modal window showing. ({window})");
            window.Show();
        }

View on GitHub (pinned to 96fad776d2)