dotnet/wpf · error · ArgumentException
SR.MalformedPropertyName
Error message
SR.MalformedPropertyName
What it means
MeScanner.ResolvePropertyName throws ArgumentException with SR.MalformedPropertyName when XamlPropertyName.Parse cannot decompose a markup-extension property name (the text between a markup extension's member references, e.g. `{x:Static Member=...}` long names) into a valid namespace/type/member form. System.Xaml uses this scanner when parsing values like `{StaticResource Key}`; a name that does not match the grammar `ns:Type.Member` or `Type.Member` is rejected. It is thrown during scanner Read, which the XAML pull parser drives, so it surfaces as an exception during XamlReader.Load/XamlXmlReader parse.
Solutions
- Fix the markup-extension property name in the XAML so it matches ns:Type.Member or Type.Member grammar.
- Ensure no leading/trailing '=' with an empty property name inside the braces.
- If the value legitimately contains '=' or braces as literal text, escape the opening brace with {} (e.g. {}{literal}) or use x:Static/attribute syntax instead.
- Re-run XamlReader.Load on a minimal snippet to isolate the offending element and line.
Example fix
<!-- before -->
<TextBlock Text="{StaticResource =HeaderKey}" />
<!-- after -->
<TextBlock Text="{StaticResource HeaderKey}" /> Defensive patterns
Strategy: try-catch
Validate before calling
if (xaml.Contains("=") && System.Text.RegularExpressions.Regex.IsMatch(xaml, @"\{[^}]*=\s*[^\w:.]")) throw new FormatException("Suspicious markup-extension property assignment"); Try / catch
try { var obj = XamlReader.Parse(xaml); } catch (XamlParseException ex) { log(ex.Message, ex.LineNumber, ex.LinePosition); } Prevention
- Author markup extensions in an XAML-aware IDE with schema validation
- Never build extension strings by raw string concatenation
- Escape literal braces with {} prefix
When it happens
Trigger: Calling XamlReader.Load / XamlXmlReader on XAML containing a markup extension whose property longName (the string before '=' inside the extension braces) does not parse — e.g. `{StaticResource =Value}` (empty name), `{StaticResource a..b=Value}`, or an unbalanced dotted name inside a markup extension property assignment.
Common situations: Hand-edited or tool-generated XAML with a typo in a markup-extension property name; string-interpolated XAML where an empty or malformed property name is emitted; WPF/.NET Core migration where previously silently-tolerated syntax is now strictly scanned.
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.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- brokenRule (SR.UnexpectedToken-based parser rule error)
- Element ::= . EmptyElement | ( StartElement ElementBody ).
- EmptyPropertyElement ::= EMPTYPROPERTYELEMENT.
- IAmbientProvider
- IXamlSchemaContextProvider
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/a28a4a29c899aaf8.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/MeScanner.cs:319
if (xamlType is null ||
// Guard against Extension getting added twice
(xamlType.UnderlyingType is not null &&
KS.Eq(xamlType.UnderlyingType.Name, typeName.Name + KnownStrings.Extension)))
{
typeName.Name = bareTypeName;
xamlType = _context.GetXamlType(typeName, true);
}
_tokenXamlType = xamlType;
_tokenNamespace = typeName.Namespace;
}
private void ResolvePropertyName(string longName)
{
XamlPropertyName propName = XamlPropertyName.Parse(longName);
if (propName is null)
{
throw new ArgumentException(SR.MalformedPropertyName);
}
XamlMember prop = null;
XamlType declaringType;
XamlType tagType = _context.CurrentType;
string tagNamespace = _context.CurrentTypeNamespace;
if (propName.IsDotted)
{
prop = _context.GetDottedProperty(tagType, tagNamespace, propName, tagIsRoot: false);
}
// Regular property p
else
{
string ns = _context.GetAttributeNamespace(propName, Namespace);
declaringType = _context.CurrentType;
prop = _context.GetNoDotAttributeProperty(declaringType, propName, Namespace, ns, tagIsRoot: false);View on GitHub (pinned to 81131a70a4)