{"record":{"id":"66a200a6438ff3ba","repo":"dotnet/wpf","slug":"sr-format-sr-missingcase-mode-tostring-writemember","errorCode":null,"errorMessage":"SR.Format(SR.MissingCase, _mode.ToString(), \"WriteMember\")","messagePattern":"SR\\.Format\\(SR\\.MissingCase, _mode\\.ToString\\(\\), \"WriteMember\"\\)","errorType":"exception","errorClass":"XamlInternalException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/DeferredWriter.cs","lineNumber":162,"sourceCode":"                {\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;\n\n            case DeferringMode.TemplateReady:\n                throw new XamlInternalException(SR.Format(SR.TemplateNotCollected, \"WriteMember\"));\n\n            case DeferringMode.TemplateDeferring:\n                _deferredWriter.WriteStartMember(property);\n                _handled = true;\n                break;\n\n            default:\n                throw new XamlInternalException(SR.Format(SR.MissingCase, _mode.ToString(), \"WriteMember\"));\n            }\n        }\n\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;","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/DeferredWriter.cs#L144-L180","documentation":"XamlInternalException with SR.MissingCase thrown from DeferredWriter.WriteStartMember when _mode holds a DeferringMode value with no switch case. This indicates the deferring state machine reached an unhandled state at a member-start write.","triggerScenarios":"WriteStartMember invoked with the writer in an unmapped DeferringMode — no code path transitioned the mode to Off, TemplateReady, TemplateStarting, or TemplateDeferring before the member write.","commonSituations":"Custom IXamlReader implementations emitting events that skip mode transitions; exception mid-template leaving the mode machine in a partial state; mixing deferring writers across threads or reusing a writer after a prior failure.","solutions":["Trace and fix the write sequence so every mode transition matches the documented template lifecycle","Do not reuse a DeferredWriter after an exception — create a fresh one","Pin/update the .NET/WPF runtime version to rule out a known framework defect","Catch XamlInternalException, log the exception message (it includes the actual _mode), and regenerate the node stream"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { deferringWriter.WriteStartMember(member); }\ncatch (XamlInternalException ex) { log.Error(\"Unhandled DeferringMode in WriteStartMember: {0}\", ex.Message); }","preventionTips":["Ensure custom IXamlReader implementations emit complete mode transitions","Create a fresh DeferredWriter after any exception","Test template serialization with the exact reader/writer combination used in production","Keep runtime versions current to avoid known state-machine bugs"],"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"}