dotnet/wpf · error · ArgumentException

SR.ReferenceIsNull (e.Property)

Error message

SR.ReferenceIsNull (e.Property)

What it means

DependencyObject.OnPropertyChanged throws ArgumentException when the incoming DependencyPropertyChangedEventArgs has a null Property. This protects subclasses overriding OnPropertyChanged from receiving/propagating malformed change notifications; the argument name 'e' is reported.

Solutions

  1. Always construct DependencyPropertyChangedEventArgs with a valid DependencyProperty
  2. Guard in calling code: check e.Property != null before forwarding notification args
  3. In overrides, let the base throw rather than swallowing — it signals a bug upstream
  4. In tests, use a real DP such as UIElement.VisibilityProperty when raising notifications

Example fix

// before
dObj.OnPropertyChanged(new DependencyPropertyChangedEventArgs()); // null Property
// after
dObj.OnPropertyChanged(new DependencyPropertyChangedEventArgs(UIElement.OpacityProperty, 0.0, 1.0));
Defensive patterns

Strategy: validation

Validate before calling

if (e.Property == null) return; // or log and skip
dObj.OnPropertyChanged(e);

Type guard

static bool IsValidArgs(in DependencyPropertyChangedEventArgs e) => e.Property != null;

Try / catch

try { base.OnPropertyChanged(e); }
catch (ArgumentException ex) when (ex.ParamName == "e") { Debug.Fail("Malformed property-changed args"); }

Prevention

When it happens

Trigger: Raising OnPropertyChanged manually (or via reflection/testing frameworks) with default(DependencyPropertyChangedEventArgs), which has a null Property; constructing event args without setting Property.

Common situations: Unit tests invoking the protected method with uninitialized args, custom property-system plumbing that forwards args without validation, serialization/deserialization of event args losing the property reference.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyObject.cs:2028

        /// </summary>
        internal virtual void EvaluateAnimatedValueCore(
                DependencyProperty  dp,
                PropertyMetadata    metadata,
            ref EffectiveValueEntry newEntry)
        {
        }

        /// <summary>
        ///     Notification that a specified property has been changed
        /// </summary>
        /// <param name="e">EventArgs that contains the property, metadata, old value, and new value for this change</param>
        protected virtual void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            // Do not call VerifyAccess because this is a virtual, and is used as a call-out.

            if( e.Property == null )
            {
                throw new ArgumentException(SR.Format(SR.ReferenceIsNull, "e.Property"), nameof(e));
            }

            if (e.IsAValueChange || e.IsASubPropertyChange || e.OperationType == OperationType.ChangeMutableDefaultValue)
            {
                // Inform per-type/property invalidation listener, if exists
                PropertyMetadata metadata = e.Metadata;
                if ((metadata != null) && (metadata.PropertyChangedCallback != null))
                {
                    metadata.PropertyChangedCallback(this, e);
                }
            }
        }

        /// <summary>
        /// Override this method to control whether a DependencyProperty should be serialized.
        /// The base implementation returns true if the property is set (locally) on this object.
        /// </summary>
        protected internal virtual bool ShouldSerializeProperty( DependencyProperty dp )

View on GitHub (pinned to 81131a70a4)