dotnet/wpf · error · XamlParseException

SR.UnRecognizedBamlNodeType

Error message

SR.UnRecognizedBamlNodeType

What it means

While reading the main BAML node loop, LoadBamlImp hits a BamlNodeType it does not recognize and throws this XamlParseException. The deserializer supports a fixed node set; an unknown node type indicates corrupt, truncated, or newer-version BAML.

Solutions

  1. Use a .NET/WPF runtime version equal to or newer than the one that compiled the BAML
  2. Recompile the resources so the BAML matches the runtime
  3. Replace the corrupted resource assembly from a known-good build
  4. Avoid third-party tools that rewrite BAML streams

Example fix

// before
// running .NET Framework 3.5 parsing BAML from .NET 4.8 build
// after
// upgrade target framework / rebuild resources with matching toolchain
Defensive patterns

Strategy: try-catch

Try / catch

try { tree = deserializer.LoadBaml(); } catch (XamlParseException ex) when (ex.Message.Contains("UnRecognizedBamlNodeType")) { log.LogError(ex); throw new ResourceLoadException("BAML version/corruption issue", ex); }

Prevention

When it happens

Trigger: BAML stream contains a node type outside the set handled by the switch (e.g. produced by a newer WPF version or corrupted bytes), encountered mid-deserialization in LoadBamlImp.

Common situations: Version mismatch: BAML compiled by a newer framework parsed by an older one; damaged satellite assembly; custom tooling rewriting BAML bytes incorrectly.

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


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/78967c63df023495. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/BamlResourceDeserializer.cs:170

                            AddChildToCurrentParent(bamlNode);
                            break;
                        }
                    case BamlNodeType.EndConstructor:
                        {
                            BamlTreeNode bamlNode = new BamlEndConstructorNode();
                            AddChildToCurrentParent(bamlNode);
                            break;
                        }
                    case BamlNodeType.EndDocument:
                        {
                            BamlTreeNode bamlNode = new BamlEndDocumentNode();
                            AddChildToCurrentParent(bamlNode);
                            PopStack();
                            break;
                        }
                    default:
                        {
                            throw new XamlParseException(SR.Format(SR.UnRecognizedBamlNodeType, _reader.NodeType));
                        }
                }

                // read properties if it has any.
                if (_reader.HasProperties)
                {
                    // The Hashtable is used to auto-number repeated properties. The usage is as the following:
                    // When encountering the 1st occurrence of the property, it stores a reference to the property's node (BamlTreeNode).
                    // When encountering the property the 2nd time, we start auto-numbering the property including the 1st occurrence
                    // and store the index count (int) in the slot from that point onwards.                                         
                    propertyOccurrences.Clear();

                    _reader.MoveToFirstProperty();
                    do
                    {
                        switch (_reader.NodeType)
                        {
                            case BamlNodeType.ConnectionId:

View on GitHub (pinned to 81131a70a4)