{"record":{"id":"64baf5aad9181852","repo":"stride3d/stride","slug":"value-cannot-be-null-parameter-source-64baf5","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'source')","messagePattern":"Value cannot be null\\. \\(Parameter 'source'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/Extensions/DependencyObjectExtensions.cs","lineNumber":24,"sourceCode":"using System.Windows;\nusing System.Reflection;\nusing System.Windows.Media;\nusing Stride.Core.Annotations;\n\nnamespace Stride.Core.Presentation.Extensions\n{\n    public static class DependencyObjectExtensions\n    {\n        /// <summary>\n        /// Retrieves the public static DependencyProperties.\n        /// </summary>\n        /// <param name=\"source\">DependencyObject that contains the DependencyProperties to be retrieved.</param>\n        /// <param name=\"includingParentProperties\">Indicates whether the DependencyProperties declared in the parent classes have to be retrieved too.</param>\n        /// <returns>Returns an array of DependencyProperty owned by the DependencyObject.</returns>\n        [NotNull]\n        public static DependencyProperty[] GetDependencyProperties([NotNull] this DependencyObject source, bool includingParentProperties = false)\n        {\n            if (source == null) throw new ArgumentNullException(nameof(source));\n\n            // there is probably a better way using TypeDescriptor\n\n            var dependencyPropertyType = typeof(DependencyProperty);\n\n            var flags = BindingFlags.Public | BindingFlags.Static;\n            if (includingParentProperties)\n                flags |= BindingFlags.FlattenHierarchy;\n\n            return source.DependencyObjectType.SystemType.GetFields(flags)\n                .Where(fi => fi.MemberType == MemberTypes.Field && fi.FieldType == dependencyPropertyType)\n                .Select(fi => (DependencyProperty)fi.GetValue(source))\n                .OrderBy(dp => dp.Name)\n                .ToArray();\n        }\n\n        /// <summary>\n        /// Sets the value of a DependencyProperty on a DependencyObject and all its logical children.","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/Extensions/DependencyObjectExtensions.cs#L6-L42","documentation":"GetDependencyProperties reflects over a DependencyObject's type to collect its DependencyProperties. It validates the source object is non-null and throws ArgumentNullException with parameter name 'source', since reflection cannot proceed without a type to inspect.","triggerScenarios":"Calling the extension GetDependencyProperties on a null DependencyObject, e.g. a template lookup or FindName result that came back null.","commonSituations":"FindName/FindResource returning null at runtime; UI element not yet loaded when the extension is invoked; passing a DataContext that failed to resolve.","solutions":["Null-check the DependencyObject before calling GetDependencyProperties.","Ensure the element exists and is loaded (e.g. call after Loaded event) before reflecting.","Fix whatever lookup returned null (name, resource key, DataContext binding)."],"exampleFix":"// before\nvar props = (control as DependencyObject).GetDependencyProperties();\n// after\nif (control is DependencyObject dep && dep != null)\n    var props = dep.GetDependencyProperties();","handlingStrategy":"type-guard","validationCode":"if (element == null) return Array.Empty<DependencyProperty>();","typeGuard":"DependencyObject EnsureVisual(DependencyObject o) => o ?? throw new ArgumentException(\"Element not found in visual tree\");","tryCatchPattern":"try { props = element.GetDependencyProperties(); } catch (ArgumentNullException ex) when (ex.ParamName == \"source\") { props = Array.Empty<DependencyProperty>(); }","preventionTips":["Resolve elements only after the visual tree is loaded","Null-check FindName/FindResource results immediately","Use 'is DependencyObject' patterns before extension calls"],"tags":["csharp","wpf","argument-null","reflection"],"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"}