MonoGame/MonoGame · error · Exception

The function cannot be completed at this time: the MessageBo

Error message

The function cannot be completed at this time: the MessageBox UI is not active.

What it means

Thrown by MessageBox.Cancel when IsVisible is false. Cancel programmatically dismisses an active message box; calling it with no box shown is a logic error.

Source

Thrown at MonoGame.Framework/Input/MessageBox.cs:64

            return result;
        }

        /// <summary>
        /// Hides the message box interface and returns the parameter as the result of <see cref="Show"/>
        /// </summary>
        /// <param name="result">Result to return</param>
        /// <exception cref="System.Exception">Thrown when the message box is not visible</exception>
        /// <example>
        /// <code>
        /// var colorTask = MessageBox.Show("Color", "What's your favorite color?", new[] { "Red", "Green", "Blue" });
        /// MessageBox.Cancel(0);
        /// var color = await colorTask;
        /// </code>
        /// </example>
        public static void Cancel(int? result)
        {
            if (!IsVisible)
                throw new Exception("The function cannot be completed at this time: the MessageBox UI is not active.");

            PlatformCancel(result);
        }
    }
}

View on GitHub (pinned to 1d71bbd0ff)

Solutions

  1. Check `MessageBox.IsVisible` before calling Cancel.
  2. Only invoke Cancel in response to an active prompt.
  3. Track prompt state in your own code.

Example fix

// before
MessageBox.Cancel(0); // no box active

// after
if (MessageBox.IsVisible)
    MessageBox.Cancel(0);
Defensive patterns

Strategy: validation

Validate before calling

if (MessageBox.IsVisible)
    MessageBox.Cancel(result);

Prevention

When it happens

Trigger: Calling MessageBox.Cancel before any Show, after the Show resolved, or from an unconditional cleanup path.

Common situations: Back/cancel handlers that always call Cancel; Dispose paths; races where the user already dismissed the box before the programmatic cancel.

Related errors


AI-assisted analysis of MonoGame/MonoGame@1d71bbd0ff (2026-08-13). Data as JSON: /api/errors/9ba297ffd5bdb3fa. Report an issue: GitHub.