{"record":{"id":"55dcffc081c654f9","repo":"dotnet/wpf","slug":"xamlxmlwriterexception-sr-format-sr-55dcff","errorCode":null,"errorMessage":"XamlXmlWriterException(SR.Format(SR.XamlXmlWriterWriteNotSupportedInCurrentState, \"WriteStartMember\"))","messagePattern":"XamlXmlWriterException\\(SR\\.Format\\(SR\\.XamlXmlWriterWriteNotSupportedInCurrentState, \"WriteStartMember\"\\)\\)","errorType":"exception","errorClass":"XamlXmlWriterException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs","lineNumber":793,"sourceCode":"                return string.Compare(x.Key, y.Key, false, TypeConverterHelper.InvariantEnglishUS);\n            }\n        }\n\n        private abstract class WriterState\n        {\n            public virtual void WriteObject(XamlXmlWriter writer, XamlType type, bool isObjectFromMember)\n            {\n                throw new XamlXmlWriterException(SR.Format(SR.XamlXmlWriterWriteNotSupportedInCurrentState, \"WriteObject\"));\n            }\n\n            public virtual void WriteEndObject(XamlXmlWriter writer)\n            {\n                throw new XamlXmlWriterException(SR.Format(SR.XamlXmlWriterWriteNotSupportedInCurrentState, \"WriteEndObject\"));\n            }\n\n            public virtual void WriteStartMember(XamlXmlWriter writer, XamlMember property)\n            {\n                throw new XamlXmlWriterException(SR.Format(SR.XamlXmlWriterWriteNotSupportedInCurrentState, \"WriteStartMember\"));\n            }\n\n            public virtual void WriteEndMember(XamlXmlWriter writer)\n            {\n                throw new XamlXmlWriterException(SR.Format(SR.XamlXmlWriterWriteNotSupportedInCurrentState, \"WriteEndMember\"));\n            }\n\n            public virtual void WriteValue(XamlXmlWriter writer, string value)\n            {\n                throw new XamlXmlWriterException(SR.Format(SR.XamlXmlWriterWriteNotSupportedInCurrentState, \"WriteValue\"));\n            }\n\n            public virtual void WriteNamespace(XamlXmlWriter writer, NamespaceDeclaration namespaceDeclaration)\n            {\n                throw new XamlXmlWriterException(SR.Format(SR.XamlXmlWriterWriteNotSupportedInCurrentState, \"WriteNamespace\"));\n            }\n\n            protected static void WriteMemberAsElement(XamlXmlWriter writer)","sourceCodeStart":775,"sourceCodeEnd":811,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs#L775-L811","documentation":"The base WriterState defines WriteStartMember to throw XamlXmlWriterException 'WriteStartMember not supported in current state'. StartMember is only valid while an object is open and no member/value write is in progress; other states keep the throwing base implementation.","triggerScenarios":"Calling WriteStartMember when no object is open (before StartObject or after EndObject), inside another member that is still open, or after the document/stream has been closed.","commonSituations":"Emitting property writes outside an object context; forgetting to EndMember before starting the next member; writing members after EndObject due to a loop-boundary bug in the emitter.","solutions":["Only call WriteStartMember between WriteStartObject/WriteGetObject and the matching WriteEndObject","Always call WriteEndMember before starting the next member","Validate node-stream ordering in your emitter (e.g. maintain a state stack mirroring the writer's)"],"exampleFix":"// before\nwriter.WriteStartObject(type);\nwriter.WriteStartMember(m1); WriteValue(v1);\nwriter.WriteStartMember(m2); // m1 not ended\n// after\nwriter.WriteStartObject(type);\nwriter.WriteStartMember(m1); WriteValue(v1); writer.WriteEndMember();\nwriter.WriteStartMember(m2); WriteValue(v2); writer.WriteEndMember();","handlingStrategy":"try-catch","validationCode":"if (state != State.InObject || state == State.InMember) throw new InvalidOperationException(\"WriteStartMember not valid here\");","typeGuard":null,"tryCatchPattern":"try { writer.WriteStartMember(member); }\ncatch (XamlXmlWriterException) { /* wrong state; fix emitter ordering */ }","preventionTips":["Only write members while an object is open","Always EndMember before the next StartMember","Maintain an explicit emitter state stack matching Start/End calls"],"tags":["xaml","invalid-state","node-stream"],"backgroundTag":"invalid-state-transition","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"}