dotnet/wpf · error · XamlParseException

SR.QuoteCharactersOutOfPlace

Error message

SR.QuoteCharactersOutOfPlace

What it means

MeScanner.ReadString accepts quote characters (' or ") only at the start of a token inside a markup extension value. If a quote appears after token characters have been read (atStart == false), the scanner throws XamlParseException with SR.QuoteCharactersOutOfPlace, because mid-token quotes would make value/argument boundaries ambiguous.

Solutions

  1. Remove or reposition the quote so it only opens/closes the whole token, not the middle.
  2. Wrap the whole value in quotes of the opposite kind, e.g. Text="{'literal with quote'}" inside extension arguments.
  3. Replace inline literal text with an XML entity (' / ") or a resource reference.
  4. Escape the outer brace with {} if the content is literal and not a markup extension at all.

Example fix

<!-- before -->
<Label Content="{StaticResource O'Brien}" />

<!-- after -->
<Label Content="{StaticResource O&apos;Brien}" />
Defensive patterns

Strategy: validation

Validate before calling

static bool HasMidTokenQuotes(string ext) { var inner = ext.Trim('{','}'); foreach (var tok in inner.Split(' ', ',')) { var t = tok.Trim(); if (t.Length > 1 && (t.StartsWith("'") ^ t.EndsWith("'"))) return false; } return true; }

Try / catch

try { return XamlReader.Parse(xaml); } catch (XamlParseException ex) { HandleParseError(ex.LineNumber, ex.LinePosition); return null; }

Prevention

When it happens

Trigger: XAML values like `{StaticResource Ke'y}` or `{Binding Path=Na"me}` where a quote character appears in the middle of an argument or after the first character of a value.

Common situations: Localized or user-supplied strings containing apostrophes placed directly inside markup extensions (e.g. `{StaticResource O'Brien}`); code-generated XAML not escaping quotes; attribute values quoted with the same character as the inner quote.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/MeScanner.cs:466

                        break;
                    case Comma:
                        done = true;  // we are done.
                        break;

                    case EqualSign:
                        _state = StringState.Property;
                        done = true;  // we are done.
                        break;

                    case Backslash:
                        escaped = true;
                        break;

                    case Quote1:
                    case Quote2:
                        if (!atStart)
                        {
                            throw new XamlParseException(this, SR.QuoteCharactersOutOfPlace);
                        }

                        quoteChar = ch;
                        wasQuoted = true;
                        break;

                    default:  // All other character (including whitespace)
                        if (_currentSpecialBracketCharacters is not null && _currentSpecialBracketCharacters.StartsEscapeSequence(ch))
                        {
                            Stack<char> bracketCharacterStack =
                                _context.CurrentBracketModeParseParameters.BracketCharacterStack;
                            bracketCharacterStack.Clear();
                            bracketCharacterStack.Push(ch);
                            _context.CurrentBracketModeParseParameters.IsBracketEscapeMode = true;
                        }

                        sb.Append(ch);
                        break;

View on GitHub (pinned to 81131a70a4)