{"record":{"id":"025a43d5d5f12f5c","repo":"AvaloniaUI/Avalonia","slug":"cannot-add-null-to-logicalchildren","errorCode":null,"errorMessage":"Cannot add null to LogicalChildren.","messagePattern":"Cannot add null to LogicalChildren\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/StyledElement.cs","lineNumber":758,"sourceCode":"        {\n            while (e != null)\n            {\n                if (e is ILogicalRoot root)\n                {\n                    return root;\n                }\n\n                e = e.StylingParent;\n            }\n\n            return null;\n        }\n\n        void IAvaloniaListItemValidator<ILogical>.Validate(ILogical item)\n        {\n            if (item is null)\n            {\n                throw new ArgumentException($\"Cannot add null to {nameof(LogicalChildren)}.\");\n            }\n        }\n\n        private void ApplyControlTheme()\n        {\n            if (GetEffectiveTheme() is { } theme)\n                ApplyControlTheme(theme, FrameType.Theme);\n        }\n\n        private void ApplyTemplatedParentControlTheme()\n        {\n            if ((TemplatedParent as StyledElement)?.GetEffectiveTheme() is { } parentTheme)\n            {\n                ApplyControlTheme(parentTheme, FrameType.TemplatedParentTheme);\n            }\n        }\n\n        private void ApplyControlTheme(ControlTheme theme, FrameType type)","sourceCodeStart":740,"sourceCodeEnd":776,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/StyledElement.cs#L740-L776","documentation":"Error \"Cannot add null to LogicalChildren.\" thrown in AvaloniaUI/Avalonia.","triggerScenarios":"Raised when null is added to a LogicalChildren collection. Defend by null-checking child elements before adding them and filtering nulls from computed child sequences.","commonSituations":"See trigger scenarios.","solutions":["Ensure the object added to LogicalChildren is not null; guard the Add call with a null check.","Fix the code path that produces a null child (e.g. a converter or template lookup returning null)."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}