dotnet/wpf · error · InvalidOperationException

SR.Format(SR.ArgumentPropertyMustNotBeNull, "Property"…

Error message

SR.Format(SR.ArgumentPropertyMustNotBeNull, "Property", "args")

What it means

OnPropertyInvalidation rejects a change-notification whose args.Property is null. The WPF property system always passes a valid DependencyProperty, so a null Property indicates a corrupted or hand-crafted DependencyPropertyChangedEventArgs, and the binding engine refuses to process it rather than fail later in a confusing way.

Solutions

  1. Ensure DependencyPropertyChangedEventArgs are created with a non-null Property (use DependencyProperty.UnsetValue/any real DP, never null)
  2. Do not invoke OnPropertyInvalidation directly; use proper APIs like InvalidateProperty or UpdateTarget
  3. Fix reflection/test helpers to construct valid args

Example fix

// before
var args = new DependencyPropertyChangedEventArgs(null, null, null);
expr.OnPropertyInvalidation(target, args); // throws
// after
var args = new DependencyPropertyChangedEventArgs(SomeProperty, oldValue, newValue);
expr.OnPropertyInvalidation(target, args);
Defensive patterns

Strategy: validation

Validate before calling

if (args.Property == null) throw new ArgumentException("DependencyPropertyChangedEventArgs.Property must not be null");

Type guard

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

Try / catch

try { expr.OnPropertyInvalidation(d, args); } catch (InvalidOperationException ex) when (ex.Message.Contains("Property")) { /* fix args construction; do not swallow */ }

Prevention

When it happens

Trigger: Invoking the binding expression's OnPropertyInvalidation (normally internal) with DependencyPropertyChangedEventArgs whose Property field was left null — only realistically via reflection, custom subclasses, or a broken internal component raising notifications.

Common situations: Rare; seen with custom framework hacks that call internal invalidation APIs, reflection-based test harnesses, or faulty third-party code simulating property changes.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingExpression.cs:212

            Worker?.RefreshValue();  // calls TransferValue
        }

#region Expression overrides

        /// <summary>
        ///     Notification that a Dependent that this Expression established has
        ///     been invalidated as a result of a Source invalidation
        /// </summary>
        /// <param name="d">DependencyObject that was invalidated</param>
        /// <param name="args">Changed event args for the property that was invalidated</param>
        internal override void OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
        {
            ArgumentNullException.ThrowIfNull(d);

            DependencyProperty dp = args.Property;
            if (dp == null)
                throw new InvalidOperationException(SR.Format(SR.ArgumentPropertyMustNotBeNull, "Property", "args"));

            // ignore irrelevant notifications.  This test must happen before any marshalling.
            bool relevant = !IgnoreSourcePropertyChange;

            if (dp == FrameworkElement.DataContextProperty && d == ContextElement)
            {
                relevant = true;    // changes from context element are always relevant
            }
            else if (dp == CollectionViewSource.ViewProperty && d == CollectionViewSource)
            {
                relevant = true;    // changes from the CollectionViewSource are always relevant
            }
            else if (dp == FrameworkElement.LanguageProperty && UsesLanguage && d == TargetElement)
            {
                relevant = true;    // changes from target's Language are always relevant
            }
            else if (relevant)
            {

View on GitHub (pinned to 81131a70a4)