dotnet/wpf · error · ArgumentException

SR.CannotBothBeNull (formatted with 'newValue'…

Error message

SR.CannotBothBeNull (formatted with 'newValue', 'previousValue')

What it means

PropertyDataChangedEventArgs represents a change of a property value, so at least one of newValue/previousValue must be non-null. The constructor throws ArgumentException when both are null because such an event conveys no change.

Solutions

  1. Supply at least one of newValue/previousValue
  2. Skip raising the event when both values are missing

Example fix

// before
new PropertyDataChangedEventArgs(guid, null, null);
// after
if (newValue != null || previousValue != null) raise(new PropertyDataChangedEventArgs(guid, newValue, previousValue));
Defensive patterns

Strategy: validation

Validate before calling

if (newValue == null && previousValue == null) return; // skip raising event

Type guard

static bool IsValidPropertyDataChange(object n, object p) => n != null || p != null;

Try / catch

try { var e = new PropertyDataChangedEventArgs(guid, newValue, previousValue); OnPropertyChangedData(e); } catch (ArgumentException) { /* nothing changed */ }

Prevention

When it happens

Trigger: Raising a PropertyDataChanged event manually with new PropertyDataChangedEventArgs(guid, null, null).

Common situations: Custom ExtendedProperties implementations forwarding change notifications with unset values; refactoring code that lost track of old/new values.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/Events.cs:103

    public delegate void PropertyDataChangedEventHandler(object sender, PropertyDataChangedEventArgs e);

    /// <summary>
    /// Event arg used a change to the drawing attributes associated with one or more strokes has occurred.
    /// </summary>
    public class PropertyDataChangedEventArgs : EventArgs
    {
        private Guid _propertyGuid;
        private object _newValue;
        private object _previousValue;

        /// <summary>Constructor</summary>
        public PropertyDataChangedEventArgs(Guid propertyGuid,
                                            object newValue,
                                            object previousValue)
        {
            if ( newValue == null && previousValue == null )
            {
                throw new ArgumentException(SR.Format(SR.CannotBothBeNull, "newValue", "previousValue"));
            }

            _propertyGuid = propertyGuid;
            _newValue = newValue;
            _previousValue = previousValue;
        }

        /// <summary>
        /// Gets the property guid that represents the DrawingAttribute that changed
        /// </summary>
        public Guid PropertyGuid
        {
            get { return _propertyGuid; }
        }

        /// <summary>
        /// Gets the new value of the DrawingAttribute
        /// </summary>

View on GitHub (pinned to 81131a70a4)