PrismLibrary/Prism · error · ArgumentNullException
raiseErrorsChanged
Error message
raiseErrorsChanged
What it means
The ErrorsContainer<T> constructor throws ArgumentNullException when the 'raiseErrorsChanged' delegate is null. This delegate is how the container notifies INotifyDataErrorInfo consumers that errors changed, so it is mandatory.
Solutions
- Pass a method group such as RaiseErrorsChanged that implements the notification
- Ensure the containing class implements INotifyDataErrorInfo and has a ErrorsChanged event to raise
- Use nameof-based wiring: new ErrorsContainer<string>(RaiseErrorsChanged)
Example fix
// before ErrorsContainer = new ErrorsContainer<string>(null); // after ErrorsContainer = new ErrorsContainer<string>(RaiseErrorsChanged);
Defensive patterns
Strategy: validation
Validate before calling
Action<string> handler = RaiseErrorsChanged;
if (handler == null)
throw new InvalidOperationException("ErrorsChanged handler must be wired before creating ErrorsContainer"); Try / catch
try
{
_errorsContainer = new ErrorsContainer<string>(RaiseErrorsChanged);
}
catch (ArgumentNullException ex)
{
logger.LogError(ex, "raiseErrorsChanged delegate was null");
} Prevention
- Follow the BindableBase pattern: wire RaiseErrorsChanged in the ViewModel base class
- Never construct ErrorsContainer with a literal null
- Keep INotifyDataErrorInfo boilerplate in one shared base class
When it happens
Trigger: Constructing new ErrorsContainer<T>(null) inside a BindableBase-derived class instead of passing an action like RaiseErrorsChanged; forgetting to wire the errors-changed callback.
Common situations: Refactoring ViewModel base classes and dropping the delegate argument; copying the ErrorsContainer pattern from documentation incompletely.
Related errors
- expression
- propertyExpression
- A dialog's ViewModel must implement the IDialogAware…
- A dialog's ViewModel must implement the IDialogAware…
- ArgumentNullException for 'regionName'
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/fdf1ebd143a52577.
Report an issue: GitHub.
Appendix: source
Thrown at src/Prism.Core/Mvvm/ErrorsContainer.cs:32
/// <summary>
/// Delegate to be called when raiseErrorsChanged is invoked.
/// </summary>
protected readonly Action<string> raiseErrorsChanged;
/// <summary>
/// A map from property name to a <see cref="List{T}"/> of the errors and sources.
/// </summary>
protected readonly Dictionary<string, List<T>> validationResults;
/// <summary>
/// Initializes a new instance of the <see cref="ErrorsContainer{T}"/> class.
/// </summary>
/// <param name="raiseErrorsChanged">The action that is invoked when errors are added for an object.</param>
public ErrorsContainer(Action<string> raiseErrorsChanged)
{
if (raiseErrorsChanged == null)
{
throw new ArgumentNullException(nameof(raiseErrorsChanged));
}
this.raiseErrorsChanged = raiseErrorsChanged;
this.validationResults = new Dictionary<string, List<T>>();
}
/// <summary>
/// Gets a value indicating whether the object has validation errors.
/// </summary>
public bool HasErrors
{
get
{
return this.validationResults.Count != 0;
}
}
/// <summary>View on GitHub (pinned to 358118cd64)