dotnet/wpf · error · NotSupportedException

NotSupportedException(SR.MissingCaseXamlNodes)

Error message

NotSupportedException(SR.MissingCaseXamlNodes)

What it means

This NotSupportedException is a defensive exhaustiveness check in XamlXmlWriter's node-dispatch switch: it fires when WriteNode processes a XamlNodeType that has no case in the switch (typically XamlNodeType.None or an unexpected node kind). It means the node stream handed to the writer contains a node type the writer never expects to see, indicating a corrupt or fabricated node stream or an internal bug.

Solutions

  1. Audit the node source so it never yields XamlNodeType.None — only valid Start/End Object/Member/Value/Namespace nodes
  2. Update System.Xaml references on both producer and consumer so node-type enums agree
  3. Wrap the reader loop to skip/filter invalid nodes before passing them to WriteNode

Example fix

// before
while (reader.Read()) { writer.WriteNode(reader); } // reader may yield None
// after
while (reader.Read()) {
    if (reader.NodeType != XamlNodeType.None) writer.WriteNode(reader);
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (reader.NodeType == XamlNodeType.None) throw new InvalidOperationException("Node stream yielded None");

Type guard

bool IsValidNode(XamlNodeType t) => t is XamlNodeType.StartObject or XamlNodeType.EndObject or XamlNodeType.StartMember or XamlNodeType.EndMember or XamlNodeType.Value or XamlNodeType.NamespaceDeclaration or XamlNodeType.GetObject;

Try / catch

try { writer.WriteNode(reader); }
catch (NotSupportedException ex) when (ex.Message.Contains("node")) { /* skip invalid node or abort with diagnostics */ }

Prevention

When it happens

Trigger: Passing a XAML node stream containing XamlNodeType.None or an unknown/future node type into XamlXmlWriter.WriteNode; a custom IXamlNodeConsumer/reader producing invalid nodes.

Common situations: Custom XamlReader implementations yielding None or uninitialized nodes; mixing node streams from different System.Xaml versions; bugs in node-buffering code that emit default-constructed XamlNodeInfo.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs:936

                        break;

                    case XamlNodeType.StartMember:
                        writer.currentState.WriteStartMember(writer, node.Member);
                        break;

                    case XamlNodeType.EndMember:
                        writer.currentState.WriteEndMember(writer);
                        break;

                    case XamlNodeType.Value:
                        writer.currentState.WriteValue(writer, node.Value as string);
                        break;

                    case XamlNodeType.None:
                        break;

                    default:
                        throw new NotSupportedException(SR.MissingCaseXamlNodes);
                }
            }
        }

        private class Start : WriterState
        {
            private static WriterState state = new Start();

            private Start() { }

            public static WriterState State
            {
                get { return state; }
            }

            public override void WriteNamespace(XamlXmlWriter writer, NamespaceDeclaration namespaceDeclaration)
            {
                Debug.Assert(writer.namespaceScopes.Count == 1);

View on GitHub (pinned to 81131a70a4)