dotnet/wpf · error · ArgumentNullException

SR.EventArgIsNull

Error message

SR.EventArgIsNull

What it means

The protected virtual OnDrawingAttributesChanged method requires a non-null PropertyDataChangedEventArgs; it throws ArgumentNullException with SR.EventArgIsNull if null is passed. Derived classes that raise the DrawingAttributesChanged event must supply a valid event-args instance.

Solutions

  1. Pass a constructed PropertyDataChangedEventArgs (oldValue, newValue, propertyGuid) to OnDrawingAttributesChanged
  2. Null-check event args in the derived raiser before calling the base method
  3. If there is nothing to report, do not call the On* method instead of passing null

Example fix

// before
OnDrawingAttributesChanged(null);
// after
OnDrawingAttributesChanged(new PropertyDataChangedEventArgs(DrawingAttributes.ColorPropertyGuid, newColor, oldColor));
Defensive patterns

Strategy: validation

Validate before calling

if (e != null) OnDrawingAttributesChanged(e); else return;

Type guard

bool CanRaise(PropertyDataChangedEventArgs e) => e != null;

Try / catch

try { OnDrawingAttributesChanged(e); } catch (ArgumentNullException ex) when (ex.ParamName == "e") { log("null event args"); }

Prevention

When it happens

Trigger: A Stroke subclass calling base.OnDrawingAttributesChanged(null), or overriding DrawingAttributes change plumbing and forwarding a null args from DrawingAttributes_Changed.

Common situations: Custom ink classes derived from Stroke raising events conditionally where the args variable was never assigned; refactoring that dropped args construction.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/4657e5c2a88099a3. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/Stroke.cs:586

        /// </summary>
        event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
        {
            add { _propertyChanged += value; }
            remove { _propertyChanged -= value; }
        }

        /// <summary>
        /// Method called on derived classes whenever a drawing attribute
        /// is changed and event listeners must be notified.
        /// </summary>
        /// <param name="e">Information on the drawing attributes that changed</param>
        /// <remarks>Derived classes should call this method (their base class)
        /// to ensure that event listeners are notified</remarks>
        protected virtual void OnDrawingAttributesChanged(PropertyDataChangedEventArgs e)
        {
            if (null == e)
            {
                throw new ArgumentNullException(nameof(e), SR.EventArgIsNull);
            }

            if (DrawingAttributesChanged != null)
            {
                DrawingAttributesChanged(this, e);
            }
        }

        /// <summary>
        /// Protected virtual version for developers deriving from InkCanvas.
        /// This method is what actually throws the event.
        /// </summary>
        /// <param name="e">DrawingAttributesReplacedEventArgs to raise the event with</param>
        protected virtual void OnDrawingAttributesReplaced(DrawingAttributesReplacedEventArgs e)
        {
            ArgumentNullException.ThrowIfNull(e);
            if (null != this.DrawingAttributesReplaced)
            {

View on GitHub (pinned to 81131a70a4)