{"record":{"id":"c5f6c3712ba684b1","repo":"dotnet/wpf","slug":"sr-format-sr-missingcase-mode-tostring-writeendmember","errorCode":null,"errorMessage":"SR.Format(SR.MissingCase, _mode.ToString(), \"WriteEndMember\")","messagePattern":"SR\\.Format\\(SR\\.MissingCase, _mode\\.ToString\\(\\), \"WriteEndMember\"\\)","errorType":"exception","errorClass":"XamlInternalException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/DeferredWriter.cs","lineNumber":183,"sourceCode":"\n        public override void WriteEndMember()\n        {\n            _handled = false;\n            switch (_mode)\n            {\n            case DeferringMode.Off:\n                break;\n\n            case DeferringMode.TemplateReady:\n                throw new XamlInternalException(SR.Format(SR.TemplateNotCollected, \"WriteEndMember\"));\n\n            case DeferringMode.TemplateDeferring:\n                _deferredWriter.WriteEndMember();\n                _handled = true;\n                break;\n\n            default:\n                throw new XamlInternalException(SR.Format(SR.MissingCase, _mode.ToString(), \"WriteEndMember\"));\n            }\n        }\n\n        public override void WriteValue(object value)\n        {\n            _handled = false;\n            switch (_mode)\n            {\n            case DeferringMode.Off:\n                break;\n\n            case DeferringMode.TemplateReady:\n                throw new XamlInternalException(SR.Format(SR.TemplateNotCollected, \"WriteValue\"));\n\n            case DeferringMode.TemplateStarting:\n                // This handles the case of SM template; V object; EM\n                Debug.Assert(_deferredTreeDepth == 0);\n                if (value is XamlNodeList)","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/DeferredWriter.cs#L165-L201","documentation":"XamlInternalException with SR.MissingCase thrown from DeferredWriter.WriteEndMember when the deferring mode matches no switch case. The default arm signals the writer's DeferringMode state machine has diverged into an unhandled state during a member-end write.","triggerScenarios":"WriteEndMember invoked while _mode is a DeferringMode value absent from the switch — the writer's internal mode tracking reached an untracked state, so the end-member event cannot be routed.","commonSituations":"Node streams from custom readers that leave the mode machine mid-transition after errors; concurrency or writer reuse issues corrupting _mode; framework updates introducing states not handled on this code path.","solutions":["Fix the producer so mode transitions follow the Off/TemplateStarting/TemplateDeferring/TemplateReady lifecycle exactly","Recreate the DeferredWriter after any failure instead of continuing to write","Apply the latest .NET/WPF servicing updates to rule out a runtime bug","Catch XamlInternalException at the serialization boundary; the message names the unexpected _mode for diagnosis"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { deferringWriter.WriteEndMember(); }\ncatch (XamlInternalException ex) { log.Error(\"Unhandled DeferringMode in WriteEndMember: {0}\", ex.Message); }","preventionTips":["Follow the documented Off/TemplateStarting/TemplateDeferring/TemplateReady lifecycle","Never reuse a DeferredWriter after a failure — create a new one","Use single-threaded access to deferring writers","Update the .NET/WPF runtime to rule out known defects"],"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"}