dotnet/wpf · error · XamlInternalException

SR.Format(SR.MissingCase, _mode.ToString(), "WriteMember")

Error message

SR.Format(SR.MissingCase, _mode.ToString(), "WriteMember")

What it means

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.

Solutions

  1. Trace and fix the write sequence so every mode transition matches the documented template lifecycle
  2. Do not reuse a DeferredWriter after an exception — create a fresh one
  3. Pin/update the .NET/WPF runtime version to rule out a known framework defect
  4. Catch XamlInternalException, log the exception message (it includes the actual _mode), and regenerate the node stream
Defensive patterns

Strategy: try-catch

Try / catch

try { deferringWriter.WriteStartMember(member); }
catch (XamlInternalException ex) { log.Error("Unhandled DeferringMode in WriteStartMember: {0}", ex.Message); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/66a200a6438ff3ba. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/DeferredWriter.cs:162

                {
                    _mode = DeferringMode.TemplateStarting;

                    // We assume in WriteValue that this property can never be multi-valued
                    Debug.Assert(!property.IsDirective && !property.IsUnknown);
                }

                break;

            case DeferringMode.TemplateReady:
                throw new XamlInternalException(SR.Format(SR.TemplateNotCollected, "WriteMember"));

            case DeferringMode.TemplateDeferring:
                _deferredWriter.WriteStartMember(property);
                _handled = true;
                break;

            default:
                throw new XamlInternalException(SR.Format(SR.MissingCase, _mode.ToString(), "WriteMember"));
            }
        }

        public override void WriteEndMember()
        {
            _handled = false;
            switch (_mode)
            {
            case DeferringMode.Off:
                break;

            case DeferringMode.TemplateReady:
                throw new XamlInternalException(SR.Format(SR.TemplateNotCollected, "WriteEndMember"));

            case DeferringMode.TemplateDeferring:
                _deferredWriter.WriteEndMember();
                _handled = true;
                break;

View on GitHub (pinned to 81131a70a4)