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

  1. Pass a method group such as RaiseErrorsChanged that implements the notification
  2. Ensure the containing class implements INotifyDataErrorInfo and has a ErrorsChanged event to raise
  3. 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

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


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)