dotnet/wpf · error · ArgumentException

SR.Format(SR.MarkupExtensionBadStatic, Member)

Error message

SR.Format(SR.MarkupExtensionBadStatic, Member)

What it means

StaticExtension.ProvideValue requires the Member string in "Type.Member" form (optionally with an XML prefix like "av:Button.Member") so it can split the declaring type from the member name. If Member contains no dot (dotIndex < 0), the split is impossible and it throws ArgumentException (SR.MarkupExtensionBadStatic, Member).

Solutions

  1. Use the full "prefix:Type.Member" form: {x:Static sys:Environment.TickCount} or {x:Static local:AppColors.BackgroundBrush}
  2. Verify the referenced member is a public static field or property on the named type
  3. If you meant a resource lookup, use {StaticResource key} instead of x:Static

Example fix

<!-- before: no dot -> ArgumentException -->
<TextBlock Text="{x:Static AppTitle}" />

<!-- after: Type.Member form -->
xmlns:local="clr-namespace:MyApp"
<TextBlock Text="{x:Static local:AppConstants.AppTitle}" />
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(member) || !member.Contains('.'))
{
    throw new ArgumentException(
        $"'{member}' is not valid for x:Static; use the form 'prefix:Type.Member'.",
        nameof(member));
}

Type guard

static bool IsWellFormedStaticMember(string member)
    => !string.IsNullOrEmpty(member) && member.IndexOf('.') > 0;

Try / catch

try
{
    value = ext.ProvideValue(serviceProvider);
}
catch (ArgumentException ex)
{
    // Member lacked the required 'Type.Member' dot form
    ReportXamlError($"Bad x:Static member: {ex.Message}", ex);
}

Prevention

When it happens

Trigger: {x:Static MyValue} or {x:Static ns:MyValue} — a Member string without a '.' separating type and member names — passed to ProvideValue during XAML parsing.

Common situations: Confusing x:Static with StaticResource and writing just a key/name; omitting the declaring type of the static member; refactoring that dropped the "Type." qualifier from the markup.

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/f1e00950d3987cd7. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Markup/StaticExtension.cs:65

                if (value != null)
                {
                    return value;
                }
            }
            else
            {
                value = SystemResourceKey.GetSystemResourceKey(Member);
                if (value != null)
                {
                    return value;
                }

                // 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 (typeString == string.Empty)
                {
                    throw new ArgumentException(SR.Format(SR.MarkupExtensionBadStatic, Member));
                }

                // Get the IXamlTypeResolver from the service provider

                ArgumentNullException.ThrowIfNull(serviceProvider);

                IXamlTypeResolver xamlTypeResolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver;
                if (xamlTypeResolver == null)
                {
                    throw new ArgumentException(SR.Format(SR.MarkupExtensionNoContext, GetType().Name, "IXamlTypeResolver"));

View on GitHub (pinned to 81131a70a4)