{"record":{"id":"fbd28a8570f80e8b","repo":"dotnet/wpf","slug":"notsupportedexception-sr-missingcasexamlnodes","errorCode":null,"errorMessage":"NotSupportedException(SR.MissingCaseXamlNodes)","messagePattern":"NotSupportedException\\(SR\\.MissingCaseXamlNodes\\)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs","lineNumber":936,"sourceCode":"                        break;\n\n                    case XamlNodeType.StartMember:\n                        writer.currentState.WriteStartMember(writer, node.Member);\n                        break;\n\n                    case XamlNodeType.EndMember:\n                        writer.currentState.WriteEndMember(writer);\n                        break;\n\n                    case XamlNodeType.Value:\n                        writer.currentState.WriteValue(writer, node.Value as string);\n                        break;\n\n                    case XamlNodeType.None:\n                        break;\n\n                    default:\n                        throw new NotSupportedException(SR.MissingCaseXamlNodes);\n                }\n            }\n        }\n\n        private class Start : WriterState\n        {\n            private static WriterState state = new Start();\n\n            private Start() { }\n\n            public static WriterState State\n            {\n                get { return state; }\n            }\n\n            public override void WriteNamespace(XamlXmlWriter writer, NamespaceDeclaration namespaceDeclaration)\n            {\n                Debug.Assert(writer.namespaceScopes.Count == 1);","sourceCodeStart":918,"sourceCodeEnd":954,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs#L918-L954","documentation":"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.","triggerScenarios":"Passing a XAML node stream containing XamlNodeType.None or an unknown/future node type into XamlXmlWriter.WriteNode; a custom IXamlNodeConsumer/reader producing invalid nodes.","commonSituations":"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.","solutions":["Audit the node source so it never yields XamlNodeType.None — only valid Start/End Object/Member/Value/Namespace nodes","Update System.Xaml references on both producer and consumer so node-type enums agree","Wrap the reader loop to skip/filter invalid nodes before passing them to WriteNode"],"exampleFix":"// before\nwhile (reader.Read()) { writer.WriteNode(reader); } // reader may yield None\n// after\nwhile (reader.Read()) {\n    if (reader.NodeType != XamlNodeType.None) writer.WriteNode(reader);\n}","handlingStrategy":"type-guard","validationCode":"if (reader.NodeType == XamlNodeType.None) throw new InvalidOperationException(\"Node stream yielded None\");","typeGuard":"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;","tryCatchPattern":"try { writer.WriteNode(reader); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"node\")) { /* skip invalid node or abort with diagnostics */ }","preventionTips":["Never yield XamlNodeType.None from custom readers","Keep System.Xaml versions aligned across producer/consumer","Validate node streams in tests with a strict reader loop"],"tags":["xaml","notsupported","node-stream"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}