{"record":{"id":"6022934f8aeb5b94","repo":"stride3d/stride","slug":"value-cannot-be-null-parameter-getparentfunc","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'getParentFunc')","messagePattern":"Value cannot be null\\. \\(Parameter 'getParentFunc'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/Extensions/DependencyObjectExtensions.cs","lineNumber":214,"sourceCode":"            }\n\n            return (T)templatePart;\n        }\n\n        #region Helper methods\n\n        /// <summary>\n        /// Find the first parent that match the given type.\n        /// </summary>\n        /// <typeparam name=\"T\">Type of parent to find.</typeparam>\n        /// <param name=\"source\">Base node from where to start looking for parent.</param>\n        /// <param name=\"getParentFunc\">Function that provide the parent element.</param>\n        /// <returns>Returns the retrieved parent, or null otherwise.</returns>\n        [CanBeNull]\n        private static T FindParentOfType<T>(DependencyObject source, [NotNull] Func<DependencyObject, DependencyObject> getParentFunc) where T : DependencyObject\n        {\n            if (source == null) throw new ArgumentNullException(nameof(source));\n            if (getParentFunc == null) throw new ArgumentNullException(nameof(getParentFunc));\n\n            while (true)\n            {\n                // try to get visual parent\n                var parent = getParentFunc(source);\n\n                if (parent != null)\n                {\n                    if (parent is T)\n                    {\n                        // parent is of requested type, returned casted\n                        return parent as T;\n                    }\n\n                    // there is a parent but not of request type, let's keep traversing the tree up\n                    source = parent;\n                    continue;\n                }","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/Extensions/DependencyObjectExtensions.cs#L196-L232","documentation":"Thrown by the private FindParentOfType<T> helper when the getParentFunc delegate is null. The delegate supplies each parent step during traversal (VisualTreeHelper.GetParent or LogicalTreeHelper.GetParent), so the helper rejects null at entry with ArgumentNullException.","triggerScenarios":"Calling FindParentOfType<T>(source, null) directly or via reflection; a misconfigured wrapper passing a null Func<DependencyObject, DependencyObject>.","commonSituations":"Refactoring a public wrapper where the tree-helper method reference was accidentally null (e.g. conditional binding or a generic indirection returning null).","solutions":["Pass a valid parent-getter such as VisualTreeHelper.GetParent or LogicalTreeHelper.GetParent","Call the public FindVisualParentOfType/FindLogicalParentOfType extensions instead of the raw helper","Assert the delegate is non-null at the wrapper level"],"exampleFix":"// before\nreturn FindParentOfType<T>(source, null);\n// after\nreturn FindParentOfType<T>(source, VisualTreeHelper.GetParent);","handlingStrategy":"validation","validationCode":"if (getParentFunc == null) getParentFunc = VisualTreeHelper.GetParent; // or throw early at the wrapper","typeGuard":"bool HasValidArgs(DependencyObject d, Func<DependencyObject, DependencyObject> f) => d != null && f != null;","tryCatchPattern":"try { return FindParentOfType<T>(source, getParentFunc); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"getParentFunc\") { return FindParentOfType<T>(source, VisualTreeHelper.GetParent); }","preventionTips":["Pass explicit tree-helper method groups (VisualTreeHelper.GetParent / LogicalTreeHelper.GetParent), never computed delegates that can be null","Default the delegate at the wrapper level instead of the call site","Use nameof-based argument checks in any new wrapper"],"tags":["null-reference","wpf","argument-null","delegate"],"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"}