{"record":{"id":"fb4832c553463937","repo":"dotnet/wpf","slug":"sr-nullparentnode","errorCode":null,"errorMessage":"SR.NullParentNode","messagePattern":"SR\\.NullParentNode","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/BamlResourceDeserializer.cs","lineNumber":315,"sourceCode":"\n            return new BamlTree(_root, _nodeCount);\n            //notice that we don't close the input stream because we don't own it.\n        }\n\n        private void PushNodeToStack(BamlTreeNode node)\n        {\n            _currentParent?.AddChild(node);\n\n            _bamlTreeStack.Push(node);\n            _currentParent = node;\n            _nodeCount++;\n        }\n\n        private void AddChildToCurrentParent(BamlTreeNode node)\n        {\n            if (_currentParent == null)\n            {\n                throw new InvalidOperationException(SR.NullParentNode);\n            }\n\n            _currentParent.AddChild(node);\n            _nodeCount++;\n        }\n\n        private void PopStack()\n        {\n            BamlTreeNode node = _bamlTreeStack.Pop();\n            if (node.Children != null)\n            {\n                // pop properties from property inheritance stack as well\n                foreach (BamlTreeNode child in node.Children)\n                {\n                    if (child is BamlStartComplexPropertyNode propertyNode)\n                    {\n                        PopPropertyFromStack(propertyNode.PropertyName);\n                    }","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/BamlResourceDeserializer.cs#L297-L333","documentation":"AddChildToCurrentParent throws this InvalidOperationException when there is no current parent node on the deserializer's stack at the time a child node is added. This reflects an internal structural invariant of the BAML tree build being violated — the tree is malformed or the deserializer state is inconsistent.","triggerScenarios":"A BAML node that adds a child arrives while the parent stack is empty — malformed BAML with unbalanced structure, or a bug/state corruption during LoadBamlImp processing.","commonSituations":"Corrupt or hand-crafted BAML with unbalanced element nesting; custom BAML writers emitting children without enclosing elements.","solutions":["Rebuild/redeploy the resource assembly to fix malformed BAML","Validate the BAML by opening the original XAML and recompiling","Avoid custom tools that emit BAML directly; stick to the XAML compiler","If reproducible with valid BAML, report as a WPF deserializer bug"],"exampleFix":"// before\n// BAML with child node outside any element\n// after\n// recompile XAML: ensure all nodes are inside a root element","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { tree = deserializer.LoadBaml(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"parent\")) { throw new ResourceLoadException(\"Malformed BAML tree structure\", ex); }","preventionTips":["Recompile malformed XAML instead of patching BAML","Use only standard XAML compilers to produce BAML","If valid BAML triggers this, file a WPF bug with the repro"],"tags":["baml","xaml","invariant","tree-structure"],"backgroundTag":"internal-invariant-violation","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"}