dotnet/wpf · error · XamlParseException
SR.InvalidEndOfBaml
Error message
SR.InvalidEndOfBaml
What it means
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.
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
Example fix
// before // reading a partially copied resources.dll // after // verify hash of resources.dll against build output before loading
Defensive patterns
Strategy: validation
Validate before calling
if (bamlStream.Length == 0 || bamlStream.Position + 1 >= bamlStream.Length) throw new IOException("BAML stream is empty or truncated"); Try / catch
try { tree = deserializer.LoadBaml(); } catch (XamlParseException ex) when (ex.Message.Contains("EndOfBaml")) { /* reload a verified copy of the resource */ } Prevention
- Verify file size/hash of resource assemblies before loading
- Never concatenate or truncate BAML streams
- Load resources only from verified build outputs
When it happens
Trigger: 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.
Common situations: Interrupted downloads/copies of resource assemblies; hand-stitched BAML; wrong resource entry read from the assembly.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- SR.InvalidStartOfBaml
- SR.UnRecognizedBamlNodeType
- Can't Assign to Known Type attributes
- Could not find prefix for type
- Found unexpected Xmlns BAML record
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/152b8e24cfab1888.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/BamlResourceDeserializer.cs:295
_reader.Name,
_reader.Value
);
AddChildToCurrentParent(bamlNode);
break;
}
default:
{
throw new XamlParseException(SR.Format(SR.UnRecognizedBamlNodeType, _reader.NodeType));
}
}
} while (_reader.MoveToNextProperty());
}
}
// At this point, the baml tree stack should be completely unwinded and also nothing more to read.
if (_reader.Read() || _bamlTreeStack.Count > 0)
{
throw new XamlParseException(SR.InvalidEndOfBaml);
}
return new BamlTree(_root, _nodeCount);
//notice that we don't close the input stream because we don't own it.
}
private void PushNodeToStack(BamlTreeNode node)
{
_currentParent?.AddChild(node);
_bamlTreeStack.Push(node);
_currentParent = node;
_nodeCount++;
}
private void AddChildToCurrentParent(BamlTreeNode node)
{
if (_currentParent == null)View on GitHub (pinned to 81131a70a4)