dotnet/wpf · error · XamlInternalException
SR.Format(SR.MissingCase, _mode.ToString()…
Error message
SR.Format(SR.MissingCase, _mode.ToString(), "WriteEndMember")
What it means
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.
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
Defensive patterns
Strategy: try-catch
Try / catch
try { deferringWriter.WriteEndMember(); }
catch (XamlInternalException ex) { log.Error("Unhandled DeferringMode in WriteEndMember: {0}", ex.Message); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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(), methodName)
- 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/c5f6c3712ba684b1.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/DeferredWriter.cs:183
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;
default:
throw new XamlInternalException(SR.Format(SR.MissingCase, _mode.ToString(), "WriteEndMember"));
}
}
public override void WriteValue(object value)
{
_handled = false;
switch (_mode)
{
case DeferringMode.Off:
break;
case DeferringMode.TemplateReady:
throw new XamlInternalException(SR.Format(SR.TemplateNotCollected, "WriteValue"));
case DeferringMode.TemplateStarting:
// This handles the case of SM template; V object; EM
Debug.Assert(_deferredTreeDepth == 0);
if (value is XamlNodeList)View on GitHub (pinned to 81131a70a4)