{"record":{"id":"5741ed3e2afb3eee","repo":"dotnet/wpf","slug":"sr-format-sr-missingcase-mode-tostring-writeendobject","errorCode":null,"errorMessage":"SR.Format(SR.MissingCase, _mode.ToString(), \"WriteEndObject\")","messagePattern":"SR\\.Format\\(SR\\.MissingCase, _mode\\.ToString\\(\\), \"WriteEndObject\"\\)","errorType":"exception","errorClass":"XamlInternalException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/DeferredWriter.cs","lineNumber":133,"sourceCode":"            case DeferringMode.TemplateReady:\n                throw new XamlInternalException(SR.Format(SR.TemplateNotCollected, \"WriteEndObject\"));\n\n            case DeferringMode.TemplateDeferring:\n                _deferredWriter.WriteEndObject();\n                _handled = true;\n                _deferredTreeDepth -= 1;\n\n                if (_deferredTreeDepth == 0)\n                {\n                    _deferredWriter.Close();\n                    _deferredWriter = null;\n                    _mode = DeferringMode.TemplateReady;\n                }\n\n                break;\n\n            default:\n                throw new XamlInternalException(SR.Format(SR.MissingCase, _mode.ToString(), \"WriteEndObject\"));\n            }\n        }\n\n        public override void WriteStartMember(XamlMember property)\n        {\n            _handled = false;\n            switch (_mode)\n            {\n            case DeferringMode.Off:\n                if (property.DeferringLoader is not null)\n                {\n                    _mode = DeferringMode.TemplateStarting;\n\n                    // We assume in WriteValue that this property can never be multi-valued\n                    Debug.Assert(!property.IsDirective && !property.IsUnknown);\n                }\n\n                break;","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/DeferredWriter.cs#L115-L151","documentation":"XamlInternalException with SR.MissingCase thrown from DeferredWriter.WriteEndObject when the deferring mode has no corresponding switch case. The default arm guards against the writer reaching an untracked DeferringMode during an object-end write.","triggerScenarios":"WriteEndObject invoked while _mode holds a value not enumerated in the switch — the writer's deferring-mode tracking no longer matches any known state at the time of the object-end write.","commonSituations":"Custom XAML readers/writers interleaving events that push the mode machine into an unmapped state; framework version mismatch where a mode added elsewhere isn't handled on this path; node streams corrupted by earlier swallowed exceptions.","solutions":["Correct the node-stream producer so deferring modes only take the documented transitions","Update to a current .NET/WPF servicing release in case of a known DeferredWriter bug","Capture the _mode value via the exception message and trace which prior write left it unmapped","Catch XamlInternalException at the serialization boundary and fall back to non-deferred serialization"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { deferringWriter.WriteEndObject(); }\ncatch (XamlInternalException ex) { log.Error(\"Unhandled DeferringMode in WriteEndObject: {0}\", ex.Message); }","preventionTips":["Follow the documented template lifecycle for all mode transitions","Update the runtime if a framework bug is suspected","Avoid reusing writers across failed serialization attempts","Capture the _mode value from the message to trace divergent transitions"],"tags":["xaml","internal-exception","deferring-writer","state-machine"],"backgroundTag":"internal-invariant-violation","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"}