{"record":{"id":"01ad1c62f3e98555","repo":"dotnet/wpf","slug":"sr-format-sr-missingcase-mode-tostring-methodname","errorCode":null,"errorMessage":"SR.Format(SR.MissingCase, _mode.ToString(), methodName)","messagePattern":"SR\\.Format\\(SR\\.MissingCase, _mode\\.ToString\\(\\), methodName\\)","errorType":"exception","errorClass":"XamlInternalException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/DeferredWriter.cs","lineNumber":103,"sourceCode":"                    _mode = DeferringMode.TemplateDeferring;\n                    goto case DeferringMode.TemplateDeferring;\n\n                case DeferringMode.TemplateDeferring:\n                    if (fromMember)\n                    {\n                        _deferredWriter.WriteGetObject();\n                    }\n                    else\n                    {\n                        _deferredWriter.WriteStartObject(xamlType);\n                    }\n\n                    _deferredTreeDepth += 1;\n                    _handled = true;\n                    break;\n\n                default:\n                    throw new XamlInternalException(SR.Format(SR.MissingCase, _mode.ToString(), methodName));\n            }\n        }\n\n        public override void WriteEndObject()\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, \"WriteEndObject\"));\n\n            case DeferringMode.TemplateDeferring:\n                _deferredWriter.WriteEndObject();\n                _handled = true;\n                _deferredTreeDepth -= 1;","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/DeferredWriter.cs#L85-L121","documentation":"XamlInternalException with SR.MissingCase thrown from DeferredWriter.WriteObject when the deferring state machine hits a _mode value not covered by its switch. This is a defensive default arm: the DeferringMode enum reached an unhandled state for this write operation.","triggerScenarios":"WriteStartObject or WriteGetObject invoked while DeferredWriter._mode holds a DeferringMode value with no switch case (any state other than Off, TemplateReady, TemplateStarting, TemplateDeferring as handled), indicating the writer's internal mode tracking diverged from the node stream.","commonSituations":"Newer DeferringMode values introduced by framework updates flowing through an older switch; corrupted or interleaved node streams from custom readers that leave the writer in an unexpected mode; bugs in custom IXamlNodePresenter implementations that toggle deferring modes manually.","solutions":["Fix the producer of the node stream so the writer's deferring mode transitions (Off/TemplateStarting/TemplateDeferring/TemplateReady) stay consistent with writes","Check the installed .NET/WPF version — a framework bug may be at fault; apply servicing updates","Reproduce with a minimal node stream and file it/inspect DeferredWriter mode transitions","Catch XamlInternalException at the save boundary and log the full node stream for diagnosis"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { deferringWriter.WriteStartObject(type); }\ncatch (XamlInternalException ex) { log.Error(\"Unhandled DeferringMode: {0}\", ex.Message); }","preventionTips":["Keep deferring-mode transitions consistent with the documented lifecycle","Pin and update the .NET/WPF runtime to serviced versions","Never interleave writes from multiple writers/readers on one DeferredWriter","Log full node streams when reproducing internal exceptions"],"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"}