{"record":{"id":"a2657a1b9a1d0c98","repo":"icsharpcode/ILSpy","slug":"unexpected-footer","errorCode":null,"errorMessage":"Unexpected footer.","messagePattern":"Unexpected footer\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"ICSharpCode.BamlDecompiler/Baml/BamlNode.cs","lineNumber":139,"sourceCode":"\t\t\t\tif (IsHeader(document[i]))\r\n\t\t\t\t{\r\n\t\t\t\t\tvar prev = current;\r\n\r\n\t\t\t\t\tcurrent = new BamlBlockNode {\r\n\t\t\t\t\t\tHeader = document[i]\r\n\t\t\t\t\t};\r\n\r\n\t\t\t\t\tif (prev != null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tprev.Children.Add(current);\r\n\t\t\t\t\t\tcurrent.Parent = prev;\r\n\t\t\t\t\t\tstack.Push(prev);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse if (IsFooter(document[i]))\r\n\t\t\t\t{\r\n\t\t\t\t\tif (current == null)\r\n\t\t\t\t\t\tthrow new Exception(\"Unexpected footer.\");\r\n\r\n\t\t\t\t\twhile (!IsMatch(current.Header, document[i]))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// End record can be omited (sometimes).\r\n\t\t\t\t\t\tif (stack.Count > 0)\r\n\t\t\t\t\t\t\tcurrent = stack.Pop();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcurrent.Footer = document[i];\r\n\t\t\t\t\tif (stack.Count > 0)\r\n\t\t\t\t\t\tcurrent = stack.Pop();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tcurrent.Children.Add(new BamlRecordNode(document[i]) { Parent = current });\r\n\t\t\t}\r\n\t\t\tDebug.Assert(stack.Count == 0);\r\n\t\t\treturn current;\r\n\t\t}\r\n\t}\r","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/icsharpcode/ILSpy/blob/60c08fcb74fcc183130f73c861ed35cf944d0bf1/ICSharpCode.BamlDecompiler/Baml/BamlNode.cs#L121-L157","documentation":"Thrown by BamlNode.Parse while building the block tree from the flat BAML record list. A 'footer' (closing) record such as ElementEnd/DocumentEnd was reached while 'current' is null, i.e. there is a closing record with no currently-open block to close. This indicates an unbalanced/malformed BAML stream.","triggerScenarios":"BAML where an end record (ElementEnd, PropertyListEnd, StaticResourceEnd, etc.) appears before any matching start/header record, so the stack of open blocks is empty at the moment a footer is processed.","commonSituations":"Corrupted or hand-edited BAML; truncated BAML resource stream; BAML produced by an unusual/custom WPF markup compiler that emits records in an order the parser does not expect.","solutions":["Re-extract the BAML resource from the original, uncorrupted assembly.","Inspect the record sequence (positions) around the failure to find the unbalanced end record.","Treat the file as unsupported/corrupt and report it rather than retrying."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    var node = BamlNode.Parse(document, token);\n} catch (Exception ex) when (!(ex is OperationCanceledException)) {\n    // document is malformed/unbalanced BAML; report position, do not retry unchanged\n    logger.Warning(\"BAML block tree parse failed: \" + ex.Message);\n}","preventionTips":["Validate BAML with IsBamlHeader before parsing.","Do not retry parsing a file that already failed unchanged; the bytes are the problem."],"tags":["baml","xaml","wpf","parsing"],"backgroundTag":null,"analyzedSha":"60c08fcb74fcc183130f73c861ed35cf944d0bf1","analyzedAt":"2026-08-13T11:34:51.223Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}