MaterialDesignInXAML/MaterialDesignInXamlToolkit · error · ArgumentNullException
All action arguments must be provided if any are provided.
Error message
All action arguments must be provided if any are provided.
What it means
The generic Enqueue<TArgument> overload requires actionContent and actionHandler to be both present or both absent (an XOR check). Supplying only one half would show a button with no handler or wire a handler with no button, so it throws ArgumentNullException naming the missing half.
Source
Thrown at src/MaterialDesignThemes.Wpf/SnackbarMessageQueue.cs:186
public void Enqueue(object content, object? actionContent, Action? actionHandler, bool promote)
=> Enqueue(content, actionContent, _ => actionHandler?.Invoke(), false, promote, false);
public void Enqueue<TArgument>(object content, object? actionContent, Action<TArgument?>? actionHandler,
TArgument? actionArgument)
=> Enqueue(content, actionContent, actionHandler, actionArgument, false, false);
public void Enqueue<TArgument>(object content, object? actionContent, Action<TArgument?>? actionHandler,
TArgument? actionArgument, bool promote) =>
Enqueue(content, actionContent, actionHandler, actionArgument, promote, false);
public void Enqueue<TArgument>(object content, object? actionContent, Action<TArgument?>? actionHandler,
TArgument? actionArgument, bool promote, bool neverConsiderToBeDuplicate, TimeSpan? durationOverride = null)
{
if (content is null) throw new ArgumentNullException(nameof(content));
if (actionContent is null ^ actionHandler is null)
{
throw new ArgumentNullException(actionContent != null ? nameof(actionContent) : nameof(actionHandler),
"All action arguments must be provided if any are provided.");
}
Action<object?>? handler = actionHandler != null
? new Action<object?>(argument => actionHandler((TArgument?)argument))
: null;
Enqueue(content, actionContent, handler, actionArgument, promote, neverConsiderToBeDuplicate, durationOverride);
}
public void Enqueue(object content, object? actionContent, Action<object?>? actionHandler,
object? actionArgument, bool promote, bool neverConsiderToBeDuplicate, TimeSpan? durationOverride = null)
{
if (content is null) throw new ArgumentNullException(nameof(content));
if (actionContent is null ^ actionHandler is null)
{
throw new ArgumentNullException(actionContent != null ? nameof(actionContent) : nameof(actionHandler),
"All action arguments must be provided if any are provided.");View on GitHub (pinned to 98edec3a0b)
Solutions
- Provide both actionContent and actionHandler, or pass null for both.
- If no action is needed, use the simpler Enqueue(content) overload.
- Centralize snackbar action creation in a helper that always pairs content and handler.
Example fix
// before
queue.Enqueue("Saved", "Undo", null);
// after
queue.Enqueue("Saved", "Undo", () => Revert()); Defensive patterns
Strategy: validation
Validate before calling
bool hasAction = actionContent is not null;
bool hasHandler = actionHandler is not null;
if (hasAction != hasHandler)
throw new ArgumentException("Provide both actionContent and actionHandler, or neither.");
queue.Enqueue(content, actionContent, actionHandler, arg, promote); Type guard
(actionContent is null) == (actionHandler is null)
Prevention
- Always pair action button text with its handler.
- Use the no-action Enqueue(content) overload when no button is needed.
- Wrap Enqueue in a helper that enforces the pairing.
When it happens
Trigger: Calling Enqueue<TArgument> with actionContent set but actionHandler null, or actionHandler set but actionContent null.
Common situations: Wiring an action button but forgetting the callback delegate; a refactor that removed the handler; conditionally providing only the button text.
Related errors
AI-assisted analysis of MaterialDesignInXAML/MaterialDesignInXamlToolkit@98edec3a0b (2026-08-13).
Data as JSON: /api/errors/f16b71c9896e9438.
Report an issue: GitHub.