dotnet/wpf · error · ArgumentException
SR.Format(SR.MarkupExtensionBadStatic, _member)
Error message
SR.Format(SR.MarkupExtensionBadStatic, _member)
What it means
StaticExtension (the XAML {x:Static} markup extension) resolves a 'Type.Member' string to a static field or property value via reflection. ProvideValue throws ArgumentException with MarkupExtensionBadStatic when the Member string contains no '.' separator, because it cannot be split into a type part and a member part. The library requires the format 'prefix:TypeName.MemberName' (prefix optional).
Solutions
- Set Member to a fully qualified 'Type.Member' string, e.g. 'local:MyClass.MyConstant' or 'System:String.Empty'.
- Validate the member string contains a '.' before calling ProvideValue.
- In XAML, fix the {x:Static} usage to include the declaring type, e.g. {x:Static sys:String.Empty}.
- If using an XML prefix, ensure the prefix is declared and the type part maps to the declaring type.
Example fix
// before
var ext = new StaticExtension("MyConstant");
// after
var ext = new StaticExtension("MyNamespace.MyClass.MyConstant"); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(member) || !member.Contains('.')) throw new ArgumentException($"Member '{member}' must be in 'Type.Member' format"); Type guard
static bool IsValidStaticMember(string? m) => !string.IsNullOrEmpty(m) && m.Contains('.'); Try / catch
try { value = ext.ProvideValue(serviceProvider); } catch (ArgumentException ex) { /* log ex.Message; surface XAML error */ } Prevention
- Always write {x:Static ns:Class.Member} with the declaring type.
- Validate member strings contain a dot before constructing StaticExtension.
- Prefer MemberType + typed code paths when the Type is already known.
When it happens
Trigger: Calling new StaticExtension(member).ProvideValue(serviceProvider) with a Member string that contains no dot, e.g. Member="Button" or Member="" — dotIndex = _member.IndexOf('.') is < 0.
Common situations: XAML files with {x:Static SomeValue} missing the type qualifier; code-built markup extensions where the member string was assembled from user input or config and the type portion was dropped; refactors that renamed types leaving a bare member name.
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
- ArgumentException(SR.Format(SR.CollectionCannotContainNulls…
- ArgumentException(SR.StringIsNullOrEmpty, nameof(fileName))
- ArgumentNullException(nameof(arrayType))
- ArgumentNullException(nameof(member))
- ArgumentNullException(nameof(value))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/3001bc99ce980e8c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/StaticExtension.cs:68
{
throw new InvalidOperationException(SR.MarkupExtensionStaticMember);
}
Type type = MemberType;
string fieldString;
string typeNameForError = null;
if (type is not null)
{
fieldString = _member;
typeNameForError = type.FullName;
}
else
{
// Validate the _member
int dotIndex = _member.IndexOf('.');
if (dotIndex < 0)
{
throw new ArgumentException(SR.Format(SR.MarkupExtensionBadStatic, _member));
}
// Pull out the type substring (this will include any XML prefix, e.g. "av:Button")
string typeString = _member.Substring(0, dotIndex);
if (string.IsNullOrEmpty(typeString))
{
throw new ArgumentException(SR.Format(SR.MarkupExtensionBadStatic, _member));
}
// Get the IXamlTypeResolver from the service provider
ArgumentNullException.ThrowIfNull(serviceProvider);
if (serviceProvider.GetService(typeof(IXamlTypeResolver)) is not IXamlTypeResolver xamlTypeResolver)
{
throw new ArgumentException(SR.Format(SR.MarkupExtensionNoContext, GetType().Name, nameof(IXamlTypeResolver)));
}
View on GitHub (pinned to 81131a70a4)