{"record":{"id":"0a6640c36f476eec","repo":"dotnet/wpf","slug":"sr-referenceisnull-e-property","errorCode":null,"errorMessage":"SR.ReferenceIsNull (e.Property)","messagePattern":"SR\\.ReferenceIsNull \\(e\\.Property\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyObject.cs","lineNumber":2028,"sourceCode":"        /// </summary>\n        internal virtual void EvaluateAnimatedValueCore(\n                DependencyProperty  dp,\n                PropertyMetadata    metadata,\n            ref EffectiveValueEntry newEntry)\n        {\n        }\n\n        /// <summary>\n        ///     Notification that a specified property has been changed\n        /// </summary>\n        /// <param name=\"e\">EventArgs that contains the property, metadata, old value, and new value for this change</param>\n        protected virtual void OnPropertyChanged(DependencyPropertyChangedEventArgs e)\n        {\n            // Do not call VerifyAccess because this is a virtual, and is used as a call-out.\n\n            if( e.Property == null )\n            {\n                throw new ArgumentException(SR.Format(SR.ReferenceIsNull, \"e.Property\"), nameof(e));\n            }\n\n            if (e.IsAValueChange || e.IsASubPropertyChange || e.OperationType == OperationType.ChangeMutableDefaultValue)\n            {\n                // Inform per-type/property invalidation listener, if exists\n                PropertyMetadata metadata = e.Metadata;\n                if ((metadata != null) && (metadata.PropertyChangedCallback != null))\n                {\n                    metadata.PropertyChangedCallback(this, e);\n                }\n            }\n        }\n\n        /// <summary>\n        /// Override this method to control whether a DependencyProperty should be serialized.\n        /// The base implementation returns true if the property is set (locally) on this object.\n        /// </summary>\n        protected internal virtual bool ShouldSerializeProperty( DependencyProperty dp )","sourceCodeStart":2010,"sourceCodeEnd":2046,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyObject.cs#L2010-L2046","documentation":"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.","triggerScenarios":"Raising OnPropertyChanged manually (or via reflection/testing frameworks) with default(DependencyPropertyChangedEventArgs), which has a null Property; constructing event args without setting Property.","commonSituations":"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.","solutions":["Always construct DependencyPropertyChangedEventArgs with a valid DependencyProperty","Guard in calling code: check e.Property != null before forwarding notification args","In overrides, let the base throw rather than swallowing — it signals a bug upstream","In tests, use a real DP such as UIElement.VisibilityProperty when raising notifications"],"exampleFix":"// before\ndObj.OnPropertyChanged(new DependencyPropertyChangedEventArgs()); // null Property\n// after\ndObj.OnPropertyChanged(new DependencyPropertyChangedEventArgs(UIElement.OpacityProperty, 0.0, 1.0));","handlingStrategy":"validation","validationCode":"if (e.Property == null) return; // or log and skip\ndObj.OnPropertyChanged(e);","typeGuard":"static bool IsValidArgs(in DependencyPropertyChangedEventArgs e) => e.Property != null;","tryCatchPattern":"try { base.OnPropertyChanged(e); }\ncatch (ArgumentException ex) when (ex.ParamName == \"e\") { Debug.Fail(\"Malformed property-changed args\"); }","preventionTips":["Never raise OnPropertyChanged with default(DependencyPropertyChangedEventArgs)","Always populate Property (and Metadata where required) in event args","Validate args in test helpers that invoke the protected method"],"tags":["wpf","dependency-property","null-argument"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}