{"record":{"id":"a51a619efb9d986a","repo":"dotnet/wpf","slug":"sr-unexpectedtokenafterme-mescanner","errorCode":null,"errorMessage":"SR.UnexpectedTokenAfterME","messagePattern":"SR\\.UnexpectedTokenAfterME","errorType":"exception","errorClass":"XamlParseException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/MeScanner.cs","lineNumber":491,"sourceCode":"                    default:  // All other character (including whitespace)\n                        if (_currentSpecialBracketCharacters is not null && _currentSpecialBracketCharacters.StartsEscapeSequence(ch))\n                        {\n                            Stack<char> bracketCharacterStack =\n                                _context.CurrentBracketModeParseParameters.BracketCharacterStack;\n                            bracketCharacterStack.Clear();\n                            bracketCharacterStack.Push(ch);\n                            _context.CurrentBracketModeParseParameters.IsBracketEscapeMode = true;\n                        }\n\n                        sb.Append(ch);\n                        break;\n                    }\n\n                    if (done)\n                    {\n                        if (braceCount > 0)\n                        {\n                            throw new XamlParseException(this, SR.UnexpectedTokenAfterME);\n                        }\n                        else\n                        {\n                            if (_context.CurrentBracketModeParseParameters?.BracketCharacterStack.Count > 0)\n                            {\n                                throw new XamlParseException(this, SR.Format(SR.MalformedBracketCharacters, ch.ToString()));\n                            }\n                        }\n\n                        PushBack();\n                        break;  // we are done.\n                    }\n                }\n\n                atStart = false;\n                Advance();\n            }\n","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/MeScanner.cs#L473-L509","documentation":"When MeScanner.ReadString reaches the end of a markup-extension value with braceCount still greater than zero (an unclosed '{' nested inside), it throws XamlParseException with SR.UnexpectedTokenAfterME. The scanner treats the extension as finished but leftover open braces mean extra/unclosed tokens follow the markup extension. System.Xaml throws this to fail fast on structurally incomplete `{}` expressions.","triggerScenarios":"XAML like `Text=\"{Binding Path={x:Static sys:Foo.Bar\"` — nested extensions not fully closed, or an inner '{' opened and the outer '}' reached first; e.g. `{StaticResource {x:Static Key` missing the inner closing brace(s).","commonSituations":"Nested markup extensions ({Binding {x:Static ...}}) hand-edited so one closing brace was deleted; template generators emitting partial extension strings; truncation when building XAML with string concatenation.","solutions":["Count and close all nested braces: every '{' inside the extension value needs its own '}'.","Simplify by removing nesting — compute the inner value as a resource and reference it once.","Use an XAML-aware editor/IDE to validate brace balance before Load.","Isolate the failing attribute by loading a minimal XAML fragment and inspect brace counts."],"exampleFix":"<!-- before -->\n<TextBlock Text=\"{Binding Path={x:Static sys:Foo.Bar}\" />\n\n<!-- after -->\n<TextBlock Text=\"{Binding Path={x:Static sys:Foo.Bar}}\" />","handlingStrategy":"validation","validationCode":"static bool BracesBalanced(string value) { int depth = 0; foreach (var c in value) { if (c=='{') depth++; else if (c=='}') depth--; if (depth<0) return false; } return depth==0; }","typeGuard":null,"tryCatchPattern":"try { return XamlReader.Parse(xaml); } catch (XamlParseException ex) { Report(ex.Message, ex.LineNumber); return null; }","preventionTips":["Count braces when nesting markup extensions","Prefer one-level extensions referencing pre-computed resources","Lint generated XAML for brace balance"],"tags":["xaml","markup-extension","unclosed-brace","parser"],"backgroundTag":"invalid-argument-format","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}