dotnet/wpf · error · XamlInternalException
SR.Format(SR.MissingCase, _mode.ToString(), methodName)
Error message
SR.Format(SR.MissingCase, _mode.ToString(), methodName)
What it means
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.
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
Defensive patterns
Strategy: try-catch
Try / catch
try { deferringWriter.WriteStartObject(type); }
catch (XamlInternalException ex) { log.Error("Unhandled DeferringMode: {0}", ex.Message); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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
- SR.Format(SR.MissingCase, _mode.ToString()…
- SR.Format(SR.MissingCase, _mode.ToString()…
- SR.Format(SR.MissingCase, _mode.ToString(), "WriteMember")
- SR.Format(SR.TemplateNotCollected, methodName)
- SR.Format(SR.TemplateNotCollected, "WriteEndMember")
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/01ad1c62f3e98555.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/DeferredWriter.cs:103
_mode = DeferringMode.TemplateDeferring;
goto case DeferringMode.TemplateDeferring;
case DeferringMode.TemplateDeferring:
if (fromMember)
{
_deferredWriter.WriteGetObject();
}
else
{
_deferredWriter.WriteStartObject(xamlType);
}
_deferredTreeDepth += 1;
_handled = true;
break;
default:
throw new XamlInternalException(SR.Format(SR.MissingCase, _mode.ToString(), methodName));
}
}
public override void WriteEndObject()
{
_handled = false;
switch (_mode)
{
case DeferringMode.Off:
break;
case DeferringMode.TemplateReady:
throw new XamlInternalException(SR.Format(SR.TemplateNotCollected, "WriteEndObject"));
case DeferringMode.TemplateDeferring:
_deferredWriter.WriteEndObject();
_handled = true;
_deferredTreeDepth -= 1;View on GitHub (pinned to 81131a70a4)