MaterialDesignInXAML/MaterialDesignInXamlToolkit · error · ArgumentNullException
session
Error message
session
What it means
ArgumentNullException(nameof(session)) in DialogClosingEventArgs constructor (DialogClosingEventArgs.cs:7). The args expose session-derived state (Cancel/Parameter) so a null session is illegal. Reachable only if user/library code constructs the args with a null session.
Source
Thrown at src/MaterialDesignThemes.Wpf/DialogClosingEventArgs.cs:7
namespace MaterialDesignThemes.Wpf;
public class DialogClosingEventArgs : RoutedEventArgs
{
public DialogClosingEventArgs(DialogSession session, RoutedEvent routedEvent)
: base(routedEvent)
=> Session = session ?? throw new ArgumentNullException(nameof(session));
/// <summary>
/// Cancel the close.
/// </summary>
public void Cancel() => IsCancelled = true;
/// <summary>
/// Indicates if the close has already been cancelled.
/// </summary>
public bool IsCancelled { get; private set; }
/// <summary>
/// Gets the parameter originally provided to <see cref="DialogHost.CloseDialogCommand"/>/
/// </summary>
public object? Parameter => Session.CloseParameter;
/// <summary>
/// Allows interaction with the current dialog session.View on GitHub (pinned to 98edec3a0b)
Solutions
- Pass a valid DialogSession when constructing DialogClosingEventArgs; reuse the host's CurrentSession.
- Raise the DialogClosing event through DialogHost's own API rather than constructing args manually.
- In tests, drive a real DialogHost lifecycle so the library constructs the args.
Defensive patterns
Strategy: validation
Validate before calling
DialogSession? session = dialogHost.CurrentSession;
if (session is null)
throw new InvalidOperationException("Cannot build DialogClosingEventArgs without a session.");
var args = new DialogClosingEventArgs(session, DialogHost.DialogClosingEvent); Type guard
static bool TryBuildClosingArgs(DialogHost host, out DialogClosingEventArgs args)
{
args = null!;
if (host.CurrentSession is null) return false;
args = new DialogClosingEventArgs(host.CurrentSession, DialogHost.DialogClosingEvent);
return true;
} Prevention
- Never construct DialogClosingEventArgs with null; reuse DialogHost.CurrentSession.
- Raise DialogClosing through the host's API, not by hand-built args.
- In tests, exercise a real DialogHost lifecycle.
When it happens
Trigger: Calling 'new DialogClosingEventArgs(null, routedEvent)' directly, or a fork raising DialogClosingEvent with a null session.
Common situations: Custom routed-event raising; test doubles; reflection instantiation; modified library builds.
Related errors
AI-assisted analysis of MaterialDesignInXAML/MaterialDesignInXamlToolkit@98edec3a0b (2026-08-13).
Data as JSON: /api/errors/7a8ea61989d37026.
Report an issue: GitHub.