dotnet/wpf · error · InvalidOperationException
InvalidOperationException(SR.Format(SR.XamlXmlWriterWriteNot…
Error message
InvalidOperationException(SR.Format(SR.XamlXmlWriterWriteNotSupportedInCurrentState, "WriteStartMember")) [implicit member, non-empty frame]
What it means
When WriteStartMember is called with an implicit property (e.g. an implicit collection/item member), XamlXmlWriter plans to merge it into the enclosing element's content. That only works when the current namespace-scope frame is empty (no open member framing); if a non-empty frame is active it throws InvalidOperationException 'WriteStartMember not supported in current state' because the implicit-member abbreviation cannot be nested inside another open member.
Solutions
- Close the currently open member with WriteEndMember before starting the implicit member
- Emit the property explicitly (real member) instead of relying on implicit-member merging when nesting is required
- Re-derive the node stream from a XamlObjectReader so implicit members appear at valid positions
Example fix
// before writer.WriteStartMember(items); // previous member still open // after writer.WriteEndMember(); writer.WriteStartMember(items); // implicit member now valid
Defensive patterns
Strategy: try-catch
Validate before calling
if (IsImplicit(property) && !currentFrameIsEmpty) throw new InvalidOperationException("Implicit member requires empty frame"); Type guard
bool CanStartImplicitMember(bool implicitProp, bool frameEmpty) => !implicitProp || frameEmpty;
Try / catch
try { writer.WriteStartMember(property); }
catch (InvalidOperationException ex) when (ex.Message.Contains("WriteStartMember")) { writer.WriteEndMember(); writer.WriteStartMember(property); } Prevention
- Close open members before starting implicit members
- Prefer explicit members when nesting is required
- Generate streams via XamlObjectReader
When it happens
Trigger: Calling WriteStartMember for an implicit property while an earlier member is still open in the current frame (namespaceScopes.Peek() not empty).
Common situations: Emitting nested implicit collections without closing prior members; hand-written node streams that skip WriteEndMember before starting an implicit member; markup expansion code writing members inside already-open members.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- IAmbientProvider
- InvalidOperationException(SR.Format(SR.XamlXmlWriterWriteNot…
- InvalidOperationException(SR.XamlTypeNameNameIsNullOrEmpty)
- InvalidOperationException(SR.XamlTypeNameNamespaceIsNull)
- IXamlSchemaContextProvider
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/1a0a3e57ad914536.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs:1041
Type = writer.namespaceScopes.Peek().Type,
});
}
writer.namespaceScopes.Peek().Member = property;
XamlType parentType = writer.namespaceScopes.Peek().Type;
if ((property == XamlLanguage.Items && parentType is not null && parentType.IsWhitespaceSignificantCollection) ||
(property == XamlLanguage.UnknownContent))
{
writer.isFirstElementOfWhitespaceSignificantCollection = true;
}
XamlType containingType = writer.namespaceScopes.Peek().Type;
if (IsImplicit(property))
{
if (!writer.namespaceScopes.Peek().IsEmpty())
{
throw new InvalidOperationException(SR.Format(SR.XamlXmlWriterWriteNotSupportedInCurrentState, "WriteStartMember"));
}
}
else if (property == containingType.ContentProperty)
{
if (!writer.namespaceScopes.Peek().IsEmpty())
{
throw new InvalidOperationException(SR.Format(SR.XamlXmlWriterWriteNotSupportedInCurrentState, "WriteStartMember"));
}
else
{
writer.currentState = TryContentProperty.State;
return;
}
}
else
{
WriteMemberAsElement(writer);
writer.WriteDeferredNamespaces(XamlNodeType.StartMember);View on GitHub (pinned to 81131a70a4)