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
- Supply at least one of newValue/previousValue
- 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
- Keep at least the old value when the new one is unknown (or vice versa)
- Guard event construction with a both-null check
- Use empty sentinels rather than null where a value is required
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
- SR.CannotBothBeNull (formatted with 'added', 'removed')
- ArgumentOutOfRangeException(nameof(oldProperty))
- ExtendedProperty is already part of the…
- GUID cannot be empty.
- InvalidMatrixContainsInfinity
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)