MaterialDesignInXAML/MaterialDesignInXamlToolkit · error · ArgumentNullException
session
Error message
session
What it means
ArgumentNullException(nameof(session)) in DialogOpenedEventArgs constructor (DialogOpenedEventArgs.cs:7). The args expose Session for interaction during the opened callback, so a null session is illegal. Reachable only when library/user code constructs DialogOpenedEventArgs with null.
Source
Thrown at src/MaterialDesignThemes.Wpf/DialogOpenedEventArgs.cs:7
namespace MaterialDesignThemes.Wpf;
public class DialogOpenedEventArgs : RoutedEventArgs
{
public DialogOpenedEventArgs(DialogSession session, RoutedEvent routedEvent)
{
if (session == null) throw new ArgumentNullException(nameof(session));
Session = session;
RoutedEvent = routedEvent;
}
/// <summary>
/// Allows interaction with the current dialog session.
/// </summary>
public DialogSession Session { get; }
}
View on GitHub (pinned to 98edec3a0b)
Solutions
- Pass a valid DialogSession when constructing DialogOpenedEventArgs; reuse DialogHost.CurrentSession.
- Subscribe to DialogOpened instead of constructing the args yourself.
- In tests, drive a real DialogHost so the library builds the args.
Defensive patterns
Strategy: validation
Validate before calling
DialogSession? session = dialogHost.CurrentSession;
if (session is null)
throw new InvalidOperationException("Cannot build DialogOpenedEventArgs without a session.");
var args = new DialogOpenedEventArgs(session, DialogHost.DialogOpenedEvent); Type guard
static bool TryBuildOpenedArgs(DialogHost host, out DialogOpenedEventArgs args)
{
args = null!;
if (host.CurrentSession is null) return false;
args = new DialogOpenedEventArgs(host.CurrentSession, DialogHost.DialogOpenedEvent);
return true;
} Prevention
- Never construct DialogOpenedEventArgs with null; reuse DialogHost.CurrentSession.
- Subscribe to DialogOpened rather than building args manually.
- In tests, drive a real DialogHost lifecycle.
When it happens
Trigger: Calling 'new DialogOpenedEventArgs(null, routedEvent)' directly, or a custom build raising DialogOpened with a null session.
Common situations: Test doubles/fakes; reflection instantiation; library forks raising the routed event manually.
Related errors
AI-assisted analysis of MaterialDesignInXAML/MaterialDesignInXamlToolkit@98edec3a0b (2026-08-13).
Data as JSON: /api/errors/0367706b375f37c3.
Report an issue: GitHub.