MaterialDesignInXAML/MaterialDesignInXamlToolkit · error · ArgumentNullException
owner
Error message
owner
What it means
ArgumentNullException(nameof(owner)) in DialogSession's internal constructor (DialogSession.cs:13). A DialogSession must reference the DialogHost that owns it; constructing one without an owner is illegal. Not reachable via public API since the constructor is internal and the host always supplies itself.
Source
Thrown at src/MaterialDesignThemes.Wpf/DialogSession.cs:13
using System.Windows.Threading;
namespace MaterialDesignThemes.Wpf;
/// <summary>
/// Allows an open dialog to be managed. Use is only permitted during a single display operation.
/// </summary>
public class DialogSession
{
private readonly DialogHost _owner;
internal DialogSession(DialogHost owner)
=> _owner = owner ?? throw new ArgumentNullException(nameof(owner));
/// <summary>
/// Indicates if the dialog session has ended. Once ended no further method calls will be permitted.
/// </summary>
/// <remarks>
/// Client code cannot set this directly, this is internally managed. To end the dialog session use <see cref="Close()"/>.
/// </remarks>
public bool IsEnded { get; internal set; }
/// <summary>
/// The parameter passed to the <see cref="DialogHost.CloseDialogCommand" /> and return by <see cref="DialogHost.Show(object)"/>
/// </summary>
internal object? CloseParameter { get; set; }
/// <summary>
/// Gets the <see cref="DialogHost.DialogContent"/> which is currently displayed, so this could be a view model or a UI element.
/// </summary>
public object? Content => _owner.DialogContent;View on GitHub (pinned to 98edec3a0b)
Solutions
- Do not construct DialogSession directly; obtain it from DialogHost.CurrentSession or the DialogOpened/Closing event args.
- If a fake is required, wrap a real DialogHost instance instead of passing null.
- Avoid reflection-based construction of internal types.
Defensive patterns
Strategy: validation
Validate before calling
DialogSession? session = dialogHost.CurrentSession;
if (session is null)
throw new InvalidOperationException("No active session to reference.");
// Use 'session'; never construct DialogSession manually. Type guard
static bool TryGetSession(DialogHost host, out DialogSession session)
{
session = host.CurrentSession!;
return session is not null;
} Prevention
- Obtain DialogSession from DialogHost.CurrentSession or event args; never construct it directly.
- Avoid reflection on internal types.
- In tests, wrap a real DialogHost rather than faking DialogSession.
When it happens
Trigger: Forks/reflection/test doubles invoking 'new DialogSession(null)'; the shipped host always passes 'this'.
Common situations: Unit-test fakes of DialogSession; reflection; modified library builds.
Related errors
AI-assisted analysis of MaterialDesignInXAML/MaterialDesignInXamlToolkit@98edec3a0b (2026-08-13).
Data as JSON: /api/errors/7b5cef40912292e6.
Report an issue: GitHub.