{"record":{"id":"db0b6db56372909f","repo":"stride3d/stride","slug":"value-cannot-be-null-parameter-property","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'property')","messagePattern":"Value cannot be null\\. \\(Parameter 'property'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/Core/DependencyPropertyWatcher.cs","lineNumber":103,"sourceCode":"                handlerRegistered = true;\n            }\n        }\n\n        private void DetachHandlers()\n        {\n            if (handlerRegistered)\n            {\n                foreach (var handler in handlers)\n                {\n                    DetachHandler(handler.Item1, handler.Item2);\n                }\n                handlerRegistered = false;\n            }\n        }\n\n        private void AttachHandler([NotNull] DependencyProperty property, [NotNull] EventHandler handler)\n        {\n            if (property == null) throw new ArgumentNullException(nameof(property));\n            if (handler == null) throw new ArgumentNullException(nameof(handler));\n            if (frameworkElement == null) throw new InvalidOperationException(\"A dependency object must be attached in order to register a handler.\");\n\n            DependencyPropertyDescriptor descriptor;\n            if (!descriptors.TryGetValue(property, out descriptor))\n            {\n                descriptor = DependencyPropertyDescriptor.FromProperty(property, AssociatedObject.GetType());\n                descriptors.Add(property, descriptor);\n            }\n            descriptor.AddValueChanged(AssociatedObject, handler);\n        }\n\n        private void DetachHandler([NotNull] DependencyProperty property, [NotNull] EventHandler handler)\n        {\n            if (property == null) throw new ArgumentNullException(nameof(property));\n            if (handler == null) throw new ArgumentNullException(nameof(handler));\n            if (frameworkElement == null) throw new InvalidOperationException(\"A dependency object must be attached in order to unregister a handler.\");\n","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/Core/DependencyPropertyWatcher.cs#L85-L121","documentation":"DependencyPropertyWatcher.AttachHandler validates that the DependencyProperty passed to it is not null and throws ArgumentNullException(nameof(property)) when it is. The watcher registers change handlers for dependency properties, and a null property cannot be mapped to a DependencyPropertyDescriptor. The library throws immediately to fail fast rather than crashing later inside the descriptor cache.","triggerScenarios":"Calling RegisterValueChangedHandler (or AttachHandlers, which enumerates watched properties) with a null DependencyProperty reference — typically because a static DependencyProperty field was null at lookup time, a dictionary/dictionary-of-properties lookup missed and returned null, or a property metadata lookup (e.g. DependencyProperty.FromName or a Find-by-name reflection call) failed silently and its null result was forwarded.","commonSituations":"XAML/BAML binding to a dependency property whose owner type or property name was renamed or moved to another assembly; reflection-based registration where typeof checks were skipped; refactoring that renamed a static DependencyProperty field while a watcher still references the old name; code running before static initializers of the owner type completed.","solutions":["Verify the DependencyProperty value passed to RegisterValueChangedHandler is non-null before calling the watcher; assert or log it at the call site.","If the property is looked up by name (DependencyProperty.FromName / reflection), check that the owner type and assembly match and that the property still exists.","Ensure the static DependencyProperty field on the owner class is initialized (correct static constructor, no field renamed/deleted).","Wrap the registration in a null check and skip with a clear diagnostic instead of letting the ArgumentNullException surface from deep inside the watcher."],"exampleFix":"// before\nwatcher.RegisterValueChangedHandler(FindProperty(\"Width\"), OnWidthChanged);\n// after\nvar prop = FindProperty(\"Width\");\nif (prop == null) throw new InvalidOperationException(\"Dependency property 'Width' not found on owner type.\");\nwatcher.RegisterValueChangedHandler(prop, OnWidthChanged);","handlingStrategy":"type-guard","validationCode":"if (property == null) throw new InvalidOperationException(\"Dependency property must be resolved before registering a watcher handler.\");","typeGuard":"static bool IsValidDependencyProperty(DependencyProperty p) => p is not null;","tryCatchPattern":"try { watcher.RegisterValueChangedHandler(prop, handler); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"property\") { log.Warn(\"Null dependency property passed to watcher\"); }","preventionTips":["Always source DependencyProperty values from static *Property fields, not name lookups.","Assert non-null property at call sites during development (Debug.Assert).","After refactoring owner types, compile-check all watcher registrations.","Resolve properties once and cache them in static readonly fields."],"tags":["wpf","argument-null","dependency-property"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}