{"record":{"id":"152b8e24cfab1888","repo":"dotnet/wpf","slug":"sr-invalidendofbaml","errorCode":null,"errorMessage":"SR.InvalidEndOfBaml","messagePattern":"SR\\.InvalidEndOfBaml","errorType":"exception","errorClass":"XamlParseException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/BamlResourceDeserializer.cs","lineNumber":295,"sourceCode":"                                        _reader.Name,\n                                        _reader.Value\n                                        );\n                                    AddChildToCurrentParent(bamlNode);\n                                    break;\n                                }\n                            default:\n                                {\n                                    throw new XamlParseException(SR.Format(SR.UnRecognizedBamlNodeType, _reader.NodeType));\n                                }\n                        }\n                    } while (_reader.MoveToNextProperty());\n                }\n            }\n\n            // At this point, the baml tree stack should be completely unwinded and also nothing more to read.\n            if (_reader.Read() || _bamlTreeStack.Count > 0)\n            {\n                throw new XamlParseException(SR.InvalidEndOfBaml);\n            }\n\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)","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/BamlResourceDeserializer.cs#L277-L313","documentation":"After the node loop finishes, LoadBamlImp expects the reader to be exhausted and the node stack empty; if either is true it throws this XamlParseException. The BAML stream ended prematurely or contained extra content.","triggerScenarios":"Truncated BAML stream (ends before all nodes are closed) or extra bytes/nodes after the document end — e.g. a partial file copy or concatenated streams.","commonSituations":"Interrupted downloads/copies of resource assemblies; hand-stitched BAML; wrong resource entry read from the assembly.","solutions":["Obtain a complete, untruncated resource assembly (verify file size/checksum)","Ensure the correct resource entry is loaded, not a partial one","Rebuild the satellite assembly","Don't concatenate or post-process BAML streams"],"exampleFix":"// before\n// reading a partially copied resources.dll\n// after\n// verify hash of resources.dll against build output before loading","handlingStrategy":"validation","validationCode":"if (bamlStream.Length == 0 || bamlStream.Position + 1 >= bamlStream.Length) throw new IOException(\"BAML stream is empty or truncated\");","typeGuard":null,"tryCatchPattern":"try { tree = deserializer.LoadBaml(); } catch (XamlParseException ex) when (ex.Message.Contains(\"EndOfBaml\")) { /* reload a verified copy of the resource */ }","preventionTips":["Verify file size/hash of resource assemblies before loading","Never concatenate or truncate BAML streams","Load resources only from verified build outputs"],"tags":["baml","xaml","localization","truncated-stream"],"backgroundTag":"schema-validation-failed","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}