{"record":{"id":"7f81792c6f5cac8f","repo":"dotnet/wpf","slug":"argumentnullexception-child","errorCode":null,"errorMessage":"ArgumentNullException: child","messagePattern":"ArgumentNullException: child","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextFlow.cs","lineNumber":905,"sourceCode":"                            {\n                                InvalidateMeasure();\n                                InvalidateVisual(); //ensure re-rendering\n                            }\n                        }\n                    }\n                }\n            }\n        }\n\n        /// <summary>\n        /// Notification that is called by Measure of a child when it ends up with \n        /// different desired size for the child. \n        /// </summary>\n        protected sealed override void OnChildDesiredSizeChanged(UIElement child)\n        {\n            if (child == null)\n            {\n                throw new ArgumentNullException(\"child\");\n            }\n\n            OnChildUIElementChanged(child);\n        }\n\n        /// <summary>\n        /// This method is called from during property invalidation time. If the FrameworkElement has a child on which\n        /// some property was invalidated and the property was marked as AffectsParentMeasure or AffectsParentArrange\n        /// during registration, this method is invoked to let a FrameworkElement know which particualr child must be\n        /// remeasured if the FrameworkElement wants to do partial (incremental) update of layout.\n        /// <para/>\n        /// Olny advanced FrameworkElement, which implement incremental update should override this method. Since\n        /// Panel always gets InvalidateMeasure or InvalidateArrange called in this situation, it ensures that\n        /// the FrameworkElement will be re-measured and/or re-arranged. Only if the FrameworkElement wants to implement a performance\n        /// optimization and avoid calling Measure/Arrange on all children, it should override this method and\n        /// store the info about invalidated children, to use subsequently in the FrameworkElement's MeasureOverride/ArrangeOverride\n        /// implementations.\n        /// <para/>","sourceCodeStart":887,"sourceCodeEnd":923,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextFlow.cs#L887-L923","documentation":"TextFlow.OnChildDesiredSizeChanged throws ArgumentNullException when the child parameter is null. The override forwards the child to OnChildUIElementChanged, which requires a real UIElement to re-measure.","triggerScenarios":"Passing null to OnChildDesiredSizeChanged directly or via layout plumbing that was handed a null child reference.","commonSituations":"Custom layout code invoking parent invalidation APIs with a stale/cleared child reference; framework interop where a child was removed before notifying the parent.","solutions":["Verify the child UIElement is non-null and still attached before notifying size changes","Skip the notification if the child reference became null (element was removed)","Fix the upstream code that produced a null child (removed/disposed element)"],"exampleFix":"// before\nflow.OnChildDesiredSizeChanged(GetChild()); // may return null\n\n// after\nvar child = GetChild();\nif (child != null) flow.OnChildDesiredSizeChanged(child);","handlingStrategy":"type-guard","validationCode":"if (child != null) flow.OnChildDesiredSizeChanged(child);","typeGuard":"bool isAttachedChild(UIElement c) => c != null && c.Parent != null;","tryCatchPattern":"try { flow.OnChildDesiredSizeChanged(child); } catch (ArgumentNullException) { /* child was detached/nulled; skip */ }","preventionTips":["Null-check child references before invalidation notifications","Keep children referenced until size-change notification completes","Detect and handle detach-then-notify ordering issues in custom panels"],"tags":["wpf","argumentnull","layout"],"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"}