dotnet/maui · error · BuildException

XC0101

XC0101

Error message

x:Static: unable to find a public -- or accessible internal -- static field, static property, const or enum value named "{0}" in "{1}".

What it means

Thrown after the type referenced by x:Static was resolved successfully but no public (or accessible internal) static field, static property, const, or enum value with the given member name was found on it. The compiler looks up both a field and a property via GetFieldReference/GetPropertyDefinition and fails only when both return null.

Source

Thrown at src/Controls/src/Build.Tasks/CompiledMarkupExtensions/StaticExtension.cs:31

		{
			INode ntype;
			if (!node.Properties.TryGetValue(new XmlName("", "Member"), out ntype))
				ntype = node.CollectionItems[0];
			var member = ((ValueNode)ntype).Value as string;

			if (IsNullOrEmpty(member) || !member.Contains("."))
				throw new BuildException(BuildExceptionCode.XStaticSyntax, node as IXmlLineInfo, null);

			var dotIdx = member.LastIndexOf('.');
			var typename = member.Substring(0, dotIdx);
			var membername = member.Substring(dotIdx + 1);

			var typeRef = module.ImportReference(XmlTypeExtensions.GetTypeReference(context.Cache, typename, module, node as BaseNode, expandToExtension: false));
			var fieldRef = GetFieldReference(context.Cache, typeRef, membername, module);
			var propertyDef = GetPropertyDefinition(context.Cache, typeRef, membername, module);

			if (fieldRef == null && propertyDef == null)
				throw new BuildException(BuildExceptionCode.XStaticResolution, node as IXmlLineInfo, null, membername, typename);

			var fieldDef = fieldRef?.Resolve();
			if (fieldRef != null)
			{
				memberRef = fieldRef.FieldType;
				if (!fieldDef.HasConstant)
					return new[] { Instruction.Create(OpCodes.Ldsfld, fieldRef) };

				//Constants can be numbers, Boolean values, strings, or a null reference. (https://msdn.microsoft.com/en-us/library/e6w8fe1b.aspx)
				if (TypeRefComparer.Default.Equals(memberRef, module.TypeSystem.Boolean))
					return [Instruction.Create(((bool)fieldDef.Constant) ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0)];
				if (TypeRefComparer.Default.Equals(memberRef, module.TypeSystem.String))
					return [Instruction.Create(OpCodes.Ldstr, (string)fieldDef.Constant)];
				if (fieldDef.Constant == null)
					return [Instruction.Create(OpCodes.Ldnull)];
				if (TypeRefComparer.Default.Equals(memberRef, module.TypeSystem.Char))
					return [Instruction.Create(OpCodes.Ldc_I4, (char)fieldDef.Constant)];
				if (TypeRefComparer.Default.Equals(memberRef, module.TypeSystem.Single))

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Open the resolved type in your IDE/object browser and confirm the exact static member name and that it is public (or internal with InternalsVisibleTo).
  2. Correct the spelling/casing of the member after the last '.'.
  3. If the member moved between types, update the typeName portion to the type that now declares it.
  4. If it is internal, add [assembly: InternalsVisibleTo("YourApp")] in the declaring assembly or expose a public wrapper.
  5. Pin/upgrade the package to the version whose API surface contains the member.

Example fix

// before
<Label Text="{x:Static sys:Math.Pi}" />   <!-- typo: Pi -->
// after
<Label Text="{x:Static sys:Math.PI}" />
Defensive patterns

Strategy: validation

Validate before calling

// Verify the static member exists and is accessible before relying on it
static bool HasPublicStaticMember(Type type, string member) =>
    type.GetMember(member, BindingFlags.Public | BindingFlags.Static)
        .Any(m => m is FieldInfo { IsLiteral: true } or FieldInfo { IsStatic: true }
               or PropertyInfo { GetMethod.IsStatic: true });

Prevention

When it happens

Trigger: Member names a private/internal static member with no InternalsVisibleTo; the member was renamed or removed in a newer package version; misspelling the member name; referencing an instance member instead of a static one; referencing a nested type instead of a value.

Common situations: Upgrading the Maui/OS package where a constant was renamed (e.g. a Colors key); referencing a static that lives on a different overload/type; using an internal helper from a third-party library without friend-assembly access; typo such as 'FontSizes.Defaultt'.

Related errors


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/b5d4786ee634e4eb. Report an issue: GitHub.