{"record":{"id":"9ba297ffd5bdb3fa","repo":"MonoGame/MonoGame","slug":"the-function-cannot-be-completed-at-this-time-the-9ba297","errorCode":null,"errorMessage":"The function cannot be completed at this time: the MessageBox UI is not active.","messagePattern":"The function cannot be completed at this time: the MessageBox UI is not active\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"MonoGame.Framework/Input/MessageBox.cs","lineNumber":64,"sourceCode":"            return result;\n        }\n\n        /// <summary>\n        /// Hides the message box interface and returns the parameter as the result of <see cref=\"Show\"/>\n        /// </summary>\n        /// <param name=\"result\">Result to return</param>\n        /// <exception cref=\"System.Exception\">Thrown when the message box is not visible</exception>\n        /// <example>\n        /// <code>\n        /// var colorTask = MessageBox.Show(\"Color\", \"What's your favorite color?\", new[] { \"Red\", \"Green\", \"Blue\" });\n        /// MessageBox.Cancel(0);\n        /// var color = await colorTask;\n        /// </code>\n        /// </example>\n        public static void Cancel(int? result)\n        {\n            if (!IsVisible)\n                throw new Exception(\"The function cannot be completed at this time: the MessageBox UI is not active.\");\n\n            PlatformCancel(result);\n        }\n    }\n}\n","sourceCodeStart":46,"sourceCodeEnd":70,"githubUrl":"https://github.com/MonoGame/MonoGame/blob/1d71bbd0ff4071a03caa583aa3bc56b85924a819/MonoGame.Framework/Input/MessageBox.cs#L46-L70","documentation":"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.","triggerScenarios":"Calling MessageBox.Cancel before any Show, after the Show resolved, or from an unconditional cleanup path.","commonSituations":"Back/cancel handlers that always call Cancel; Dispose paths; races where the user already dismissed the box before the programmatic cancel.","solutions":["Check `MessageBox.IsVisible` before calling Cancel.","Only invoke Cancel in response to an active prompt.","Track prompt state in your own code."],"exampleFix":"// before\nMessageBox.Cancel(0); // no box active\n\n// after\nif (MessageBox.IsVisible)\n    MessageBox.Cancel(0);","handlingStrategy":"validation","validationCode":"if (MessageBox.IsVisible)\n    MessageBox.Cancel(result);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guard Cancel calls with IsVisible.","Only Cancel in response to an active box.","Track prompt liveness in your own state."],"tags":["monogame","input","ui","state"],"backgroundTag":null,"analyzedSha":"1d71bbd0ff4071a03caa583aa3bc56b85924a819","analyzedAt":"2026-08-13T17:10:33.625Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}