{"record":{"id":"e94e99281b1e5fde","repo":"dotnet/wpf","slug":"sr-parserabandonedtypeconvertertext","errorCode":null,"errorMessage":"SR.ParserAbandonedTypeConverterText","messagePattern":"SR\\.ParserAbandonedTypeConverterText","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs","lineNumber":6023,"sourceCode":"                }\n            }\n\n            // Called when we know a type converter will not be used.  This is called from\n            //  inside this class if any part of the syntax fails.  It may be called from\n            //  outside this class if caller determines that a TypeConverter is not applicable.\n            // For example, when text is deemed to be content and not TypeConverter input.\n            internal void ResetTypeConverterDecision()\n            {\n                if(_typeConverterTextWrittenAndNotProcessed != null)\n                {\n                    // This means we were expecting to use TypeConverter, we had\n                    //  written out a text XamlNode expecting to use it, but we\n                    //  came across something else that broke our ability to use\n                    //  TypeConverter.\n\n                    // Example that would trip this error:\n                    //  <FontFamily>Symbol<FontFamily.Baseline>12.345</FontFamily.Baseline></FontFamily>\n                    throw new InvalidOperationException(SR.Format(SR.ParserAbandonedTypeConverterText,_typeConverterTextWrittenAndNotProcessed));\n                }\n                _typeConverterDecisionState = TypeConverterDecisionState.Uninitialized;\n                _typeConverterCandidateIndex = 0;\n                _typeConverterTextWrittenAndNotProcessed = null;\n            }\n\n            // Called by CompileText (or helper methods) when they are sending text\n            //  that they think is TypeConverter input.  For proper TypeConverter\n            //  syntax, we must be at a point where we're processing ElementStart.\n            internal void WritingTypeConverterText(string initializationText)\n            {\n                if( _typeConverterDecisionState != TypeConverterDecisionState.ElementStart )\n                {\n                    // Example that would trip this error:\n                    //  <FontFamily Baseline=\"12.345\">Symbol</FontFamily>\n                    throw new InvalidOperationException(SR.Format(SR.ParserTypeConverterTextUnusable,initializationText));\n                }\n","sourceCodeStart":6005,"sourceCodeEnd":6041,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs#L6005-L6041","documentation":"InvalidOperationException with SR.ParserAbandonedTypeConverterText thrown when the parser wrote out text nodes destined for a TypeConverter but encountered something else that made that text unusable before it could be processed, so the buffered converter text is abandoned.","triggerScenarios":"Parsing XAML like <FontFamily>Symbol<FontFamily.Baseline>12.345</FontFamily.Baseline></FontFamily> — text written for the element's TypeConverter, followed by a property element or other node that breaks the converter text usage, inside XamlReaderHelper's type-converter decision state machine.","commonSituations":"Mixing inline text (converted via TypeConverter) with child property elements on the same element, e.g. text content plus property element children on a type whose constructor text conversion expects the whole content.","solutions":["Move the inline text out of the element into a property element or attribute (e.g. <FontFamily><FontFamily.Family>Symbol</FontFamily.Family></FontFamily> is not valid; instead set text-only or use attributes).","Remove or relocate the child property element that interrupts the text content.","Use a constructor that accepts the value explicitly instead of TypeConverter text conversion.","Restructure the XAML so text content elements contain only text."],"exampleFix":"// before\n<FontFamily>Symbol<FontFamily.Baseline>12.345</FontFamily.Baseline></FontFamily>\n// after\n<FontFamily>Symbol</FontFamily>","handlingStrategy":"try-catch","validationCode":"// don't mix text content and child property elements on converter-driven elements\nbool hasText = el.Nodes().OfType<XText>().Any(n => !string.IsNullOrWhiteSpace(n.Value));\nbool hasProps = el.Elements().Any();\nif (hasText && hasProps) throw new InvalidOperationException($\"<{el.Name}> cannot mix text and property elements\");","typeGuard":null,"tryCatchPattern":"try { return (T)XamlReader.Parse(xaml); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"TypeConverter\")) { log.Error(ex.Message); throw; }","preventionTips":["Element text content should be the only content when a TypeConverter drives it.","Move extra values to attributes or separate elements.","Review markup for text plus property-element mixing."],"tags":["wpf","xaml","typeconverter","parsing"],"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"}