{"record":{"id":"d0abfbdaaf9a82e1","repo":"MaterialDesignInXAML/MaterialDesignInXamlToolkit","slug":"dialog-session-has-ended","errorCode":null,"errorMessage":"Dialog session has ended.","messagePattern":"Dialog session has ended\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/MaterialDesignThemes.Wpf/DialogSession.cs","lineNumber":53,"sourceCode":"    /// </summary>\n    /// <param name=\"content\"></param>\n    public void UpdateContent(object? content)\n    {\n        _owner.AssertTargetableContent();\n        _owner.DialogContent = content;\n        _owner.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>\n        {\n            _owner.FocusPopup();\n        }));\n    }\n\n    /// <summary>\n    /// Closes the dialog.\n    /// </summary>\n    /// <exception cref=\"InvalidOperationException\">Thrown if the dialog session has ended, or a close operation is currently in progress.</exception>\n    public void Close()\n    {\n        if (IsEnded) throw new InvalidOperationException(\"Dialog session has ended.\");\n\n        _owner.InternalClose(null);\n    }\n\n    /// <summary>\n    /// Closes the dialog.\n    /// </summary>\n    /// <param name=\"parameter\">Result parameter which will be returned in <see cref=\"DialogClosingEventArgs.Parameter\"/> or from <see cref=\"DialogHost.Show(object)\"/> method.</param>\n    /// <exception cref=\"InvalidOperationException\">Thrown if the dialog session has ended, or a close operation is currently in progress.</exception>\n    public void Close(object? parameter)\n    {\n        if (IsEnded) throw new InvalidOperationException(\"Dialog session has ended.\");\n\n        _owner.InternalClose(parameter);\n    }\n}\n","sourceCodeStart":35,"sourceCodeEnd":70,"githubUrl":"https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/98edec3a0b96ef272c587b14bcd67ef5f928a7ed/src/MaterialDesignThemes.Wpf/DialogSession.cs#L35-L70","documentation":"InvalidOperationException('Dialog session has ended.') from DialogSession.Close() (DialogSession.cs:53). Once IsEnded is true (set during the closing sequence), no further Close calls are accepted. Calling Close() after the dialog already closed throws.","triggerScenarios":"Invoking session.Close() after the session has ended: double-close, closing from a timer/command that fires after dismissal, or calling Close from inside a closing callback that already ended the session.","commonSituations":"Rapid double-click on a close button whose command calls session.Close; delayed/async close logic firing after the dialog is gone; close from a background dispatcher tick.","solutions":["Guard with 'if (!session.IsEnded) session.Close();' before closing.","Disable the close button/command after first invocation.","Avoid calling session.Close from within DialogClosing/DialogClosed handlers where the session is already ending."],"exampleFix":"// before\nprivate void CloseClick() => _session.Close(); // throws on second click\n\n// after\nprivate void CloseClick()\n{\n    if (_session is { IsEnded: false } s)\n        s.Close();\n}","handlingStrategy":"validation","validationCode":"if (session is { IsEnded: false })\n    session.Close();","typeGuard":"static bool CanCloseSession(DialogSession? session) => session is { IsEnded: false };","tryCatchPattern":"try\n{\n    session.Close();\n}\ncatch (InvalidOperationException ex) when (ex.Message == \"Dialog session has ended.\")\n{\n    // already closed; ignore\n}","preventionTips":["Check 'session.IsEnded' before calling Close.","Make close buttons/commands single-shot (disable after first click).","Do not call session.Close from within DialogClosing/DialogClosed handlers."],"tags":["wpf","materialdesigninxaml","dialog","state","lifecycle"],"backgroundTag":null,"analyzedSha":"98edec3a0b96ef272c587b14bcd67ef5f928a7ed","analyzedAt":"2026-08-13T14:31:19.111Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}