icsharpcode/ILSpy · error · Exception

Unexpected footer.

Error message

Unexpected footer.

What it means

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.

Source

Thrown at ICSharpCode.BamlDecompiler/Baml/BamlNode.cs:139

				if (IsHeader(document[i]))
				{
					var prev = current;

					current = new BamlBlockNode {
						Header = document[i]
					};

					if (prev != null)
					{
						prev.Children.Add(current);
						current.Parent = prev;
						stack.Push(prev);
					}
				}
				else if (IsFooter(document[i]))
				{
					if (current == null)
						throw new Exception("Unexpected footer.");

					while (!IsMatch(current.Header, document[i]))
					{
						// End record can be omited (sometimes).
						if (stack.Count > 0)
							current = stack.Pop();
					}
					current.Footer = document[i];
					if (stack.Count > 0)
						current = stack.Pop();
				}
				else
					current.Children.Add(new BamlRecordNode(document[i]) { Parent = current });
			}
			Debug.Assert(stack.Count == 0);
			return current;
		}
	}

View on GitHub (pinned to 60c08fcb74)

Solutions

  1. Re-extract the BAML resource from the original, uncorrupted assembly.
  2. Inspect the record sequence (positions) around the failure to find the unbalanced end record.
  3. Treat the file as unsupported/corrupt and report it rather than retrying.
Defensive patterns

Strategy: try-catch

Try / catch

try {
    var node = BamlNode.Parse(document, token);
} catch (Exception ex) when (!(ex is OperationCanceledException)) {
    // document is malformed/unbalanced BAML; report position, do not retry unchanged
    logger.Warning("BAML block tree parse failed: " + ex.Message);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of icsharpcode/ILSpy@60c08fcb74 (2026-08-13). Data as JSON: /api/errors/a2657a1b9a1d0c98. Report an issue: GitHub.