stride3d/stride · error · InvalidOperationException
Invoking ShouldStayOpen before the work is finished.
Error message
Invoking ShouldStayOpen before the work is finished.
What it means
WorkProgressViewModel.ShouldStayOpen() decides whether the progress window should remain visible after a work item completes. The library throws InvalidOperationException if called before WorkDone is true, because the keep-open decision is only meaningful for finished work. It is a guard against querying an unfinished progress state.
Solutions
- Ensure ShouldStayOpen() is only invoked after WorkDone becomes true (e.g. await the work task before querying).
- Move the call into the work-completed callback/continuation instead of polling.
- Guard the call with an if (vm.WorkDone) check and defer otherwise.
- Catch InvalidOperationException and treat it as 'not ready yet' if early calls are unavoidable.
Example fix
// before
if (!progressViewModel.ShouldStayOpen())
window.Close();
// after
await workTask;
if (progressViewModel.WorkDone && !progressViewModel.ShouldStayOpen())
window.Close(); Defensive patterns
Strategy: validation
Validate before calling
if (!progressViewModel.WorkDone) throw new InvalidOperationException("Work is not finished yet; defer ShouldStayOpen");
var stayOpen = progressViewModel.ShouldStayOpen(); Try / catch
try { stayOpen = vm.ShouldStayOpen(); }
catch (InvalidOperationException) { stayOpen = true; /* window stays until work done */ } Prevention
- Only call ShouldStayOpen from the work-completed continuation
- Never poll ShouldStayOpen while work is running
- Check WorkDone before any keep-open logic
When it happens
Trigger: Calling ShouldStayOpen() while the associated work is still executing (WorkDone == false), typically from UI code that polls the window state too early or before awaiting the work's completion.
Common situations: A developer wires the progress dialog close logic in the window's Closing handler while the background task is still running; or an editor plugin checks keep-open behavior immediately after ShowProgressWindow without waiting for the operation to finish.
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
- This instance doesn't contain any path. Use Push() methods…
- Item belongs to another PriorityNodeQueue.
- Parent cannot be null
- The folder being deleted is not empty.
- The entity to insert has already been destroyed
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/db99388e5df092a8.
Report an issue: GitHub.
Appendix: source
Thrown at sources/editor/Stride.Core.Assets.Editor/ViewModel/Progress/WorkProgressViewModel.cs:204
public void RegisterProgressStatus(IProgressStatus progressStatus, bool updateAsync)
{
registeredProgressStatus = progressStatus;
progressStatusUpdateAsync = updateAsync;
progressStatus.ProgressChanged += ProgressChanged;
Minimum = 0;
Maximum = 1;
}
/// <summary>
/// Indicates whether the progress window should stay open.
/// This method throws an exception if invoked when <see cref="WorkDone"/> is false.
/// </summary>
/// <returns><c>true</c> if the window should stay open, <c>false</c> otherwise.</returns>
public bool ShouldStayOpen()
{
if (!WorkDone)
{
throw new InvalidOperationException("Invoking ShouldStayOpen before the work is finished.");
}
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()View on GitHub (pinned to 96fad776d2)