dotnet/wpf · error · InvalidOperationException

SR.ParserAbandonedTypeConverterText

Error message

SR.ParserAbandonedTypeConverterText

What it means

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.

Solutions

  1. 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).
  2. Remove or relocate the child property element that interrupts the text content.
  3. Use a constructor that accepts the value explicitly instead of TypeConverter text conversion.
  4. Restructure the XAML so text content elements contain only text.

Example fix

// before
<FontFamily>Symbol<FontFamily.Baseline>12.345</FontFamily.Baseline></FontFamily>
// after
<FontFamily>Symbol</FontFamily>
Defensive patterns

Strategy: try-catch

Validate before calling

// don't mix text content and child property elements on converter-driven elements
bool hasText = el.Nodes().OfType<XText>().Any(n => !string.IsNullOrWhiteSpace(n.Value));
bool hasProps = el.Elements().Any();
if (hasText && hasProps) throw new InvalidOperationException($"<{el.Name}> cannot mix text and property elements");

Try / catch

try { return (T)XamlReader.Parse(xaml); } catch (InvalidOperationException ex) when (ex.Message.Contains("TypeConverter")) { log.Error(ex.Message); throw; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/e94e99281b1e5fde. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs:6023

                }
            }

            // Called when we know a type converter will not be used.  This is called from
            //  inside this class if any part of the syntax fails.  It may be called from
            //  outside this class if caller determines that a TypeConverter is not applicable.
            // For example, when text is deemed to be content and not TypeConverter input.
            internal void ResetTypeConverterDecision()
            {
                if(_typeConverterTextWrittenAndNotProcessed != null)
                {
                    // This means we were expecting to use TypeConverter, we had
                    //  written out a text XamlNode expecting to use it, but we
                    //  came across something else that broke our ability to use
                    //  TypeConverter.

                    // Example that would trip this error:
                    //  <FontFamily>Symbol<FontFamily.Baseline>12.345</FontFamily.Baseline></FontFamily>
                    throw new InvalidOperationException(SR.Format(SR.ParserAbandonedTypeConverterText,_typeConverterTextWrittenAndNotProcessed));
                }
                _typeConverterDecisionState = TypeConverterDecisionState.Uninitialized;
                _typeConverterCandidateIndex = 0;
                _typeConverterTextWrittenAndNotProcessed = null;
            }

            // Called by CompileText (or helper methods) when they are sending text
            //  that they think is TypeConverter input.  For proper TypeConverter
            //  syntax, we must be at a point where we're processing ElementStart.
            internal void WritingTypeConverterText(string initializationText)
            {
                if( _typeConverterDecisionState != TypeConverterDecisionState.ElementStart )
                {
                    // Example that would trip this error:
                    //  <FontFamily Baseline="12.345">Symbol</FontFamily>
                    throw new InvalidOperationException(SR.Format(SR.ParserTypeConverterTextUnusable,initializationText));
                }

View on GitHub (pinned to 81131a70a4)