dotnet/wpf · error · ArgumentNullException

SR.EventArgIsNull

Error message

SR.EventArgIsNull

What it means

DrawingAttributes.OnAttributeChanged throws ArgumentNullException with SR.EventArgIsNull when the PropertyDataChangedEventArgs passed in is null. This protected virtual method is the raise-point for the AttributeChanged event, and a null event-args instance would make downstream handlers fail obscurely, so it is rejected at the entry. It is normally invoked via the ExtendedPropertiesChanged_EventForwarder when an attribute in the underlying collection changes.

Solutions

  1. Never invoke OnAttributeChanged with null; construct a valid PropertyDataChangedEventArgs describing the change.
  2. If the change carries no data, do not raise the event at all rather than raising with null args.
  3. In subclass overrides calling base.OnAttributeChanged, guard the args or let the ArgumentNullException surface as a bug signal.

Example fix

// before
protected override void OnAttributeChanged(PropertyDataChangedEventArgs e)
{
    base.OnAttributeChanged(null); // ArgumentNullException
}
// after
protected override void OnAttributeChanged(PropertyDataChangedEventArgs e)
{
    if (e != null) base.OnAttributeChanged(e);
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (e == null) throw new ArgumentNullException(nameof(e)); // or skip raising
base.OnAttributeChanged(e);

Type guard

static bool IsValidArgs(PropertyDataChangedEventArgs e) => e != null;

Try / catch

try { OnAttributeChanged(args); }
catch (ArgumentNullException) { /* args was null; construct a valid PropertyDataChangedEventArgs or skip the raise */ }

Prevention

When it happens

Trigger: Calling OnAttributeChanged(null) — usually from a subclass override forwarding events, or from test/infrastructure code that constructs the change notification manually with a null args.

Common situations: Custom DrawingAttributes subclasses forwarding ExtendedPropertiesChanged notifications without checking the args; refactors where the event-args construction was moved but a null path remained.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/DrawingAttributes.cs:590

        }
        #endregion

        #region Events

        /// <summary>
        /// Event fired whenever a DrawingAttribute is modified
        /// </summary>
        public event PropertyDataChangedEventHandler AttributeChanged;

        /// <summary>
        /// Method called when a change occurs to any DrawingAttribute
        /// </summary>
        /// <param name="e">The change information for the DrawingAttribute that was modified</param>
        protected virtual void OnAttributeChanged(PropertyDataChangedEventArgs e)
        {
            if (null == e)
            {
                throw new ArgumentNullException(nameof(e), SR.EventArgIsNull);
            }

            try
            {
                PrivateNotifyPropertyChanged(e);
            }
            finally
            {
                if ( this.AttributeChanged != null )
                {
                    this.AttributeChanged(this, e);
                }
            }
        }

         /// <summary>
        /// Event fired whenever a DrawingAttribute is modified
        /// </summary>

View on GitHub (pinned to 81131a70a4)