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

  1. Do not construct DialogSession directly; obtain it from DialogHost.CurrentSession or the DialogOpened/Closing event args.
  2. If a fake is required, wrap a real DialogHost instance instead of passing null.
  3. 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

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.