dotnet/maui · error · BuildException

XC0006

XC0006

Error message

No static method found for "{0}::{1} ({2})".

What it means

Thrown when an element declares x:FactoryMethod but no public static method with that name on the type matches the supplied x:Arguments (or no such static method exists at all). CreateObjectVisitor searches AllMethods for a non-constructor static method whose name and arguments line up.

Source

Thrown at src/Controls/src/Build.Tasks/CreateObjectVisitor.cs:142

			if (node.Properties.ContainsKey(XmlName.xArguments) && !node.Properties.ContainsKey(XmlName.xFactoryMethod))
			{
				factoryCtorInfo = typedef.AllMethods(Context.Cache).FirstOrDefault(md => md.methodDef.IsConstructor &&
																			!md.methodDef.IsStatic &&
																			md.methodDef.HasParameters &&
																			md.methodDef.MatchXArguments(node, typeref, Module, Context)).methodDef;
				ctorInfo = factoryCtorInfo ?? throw new BuildException(BuildExceptionCode.ConstructorXArgsMissing, node, null, typedef.FullName);
				if (!typedef.IsValueType) //for ctor'ing typedefs, we first have to ldloca before the params
					Context.IL.Append(PushCtorXArguments(factoryCtorInfo.ResolveGenericParameters(typeref, Module), node));
			}
			else if (node.Properties.TryGetValue(XmlName.xFactoryMethod, out INode value))
			{
				var factoryMethod = (string)(value as ValueNode).Value;
				factoryMethodInfo = typedef.AllMethods(Context.Cache).FirstOrDefault(md => !md.methodDef.IsConstructor &&
																			  md.methodDef.Name == factoryMethod &&
																			  md.methodDef.IsStatic &&
																			  md.methodDef.MatchXArguments(node, typeref, Module, Context)).methodDef;
				if (factoryMethodInfo == null)
					throw new BuildException(BuildExceptionCode.MethodStaticMissing, node, null, typedef.FullName, factoryMethod, null);

				Context.IL.Append(PushCtorXArguments(factoryMethodInfo.ResolveGenericParameters(typeref, Module), node));
			}
			if (ctorInfo == null && factoryMethodInfo == null)
			{
				parameterizedCtorInfo = typedef.Methods.FirstOrDefault(md => md.IsConstructor &&
																			 !md.IsStatic &&
																			 md.HasParameters &&
																			 md.Parameters.All(
																				 pd =>
																					 pd.CustomAttributes.Any(
																						 ca =>
																							 ca.AttributeType.FullName ==
																							 "Microsoft.Maui.Controls.ParameterAttribute")));
			}
			string missingCtorParameter = null;
			if (parameterizedCtorInfo != null && ValidateCtorArguments(parameterizedCtorInfo, node, out missingCtorParameter))
			{

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Confirm the method is public and static and its parameter types match x:Arguments exactly.
  2. Correct the spelling/casing of the method name.
  3. If only an instance factory exists, instantiate first then call it, or add a static wrapper.
  4. Pin/upgrade the package to a version exposing the expected factory signature.

Example fix

// before
<Widget x:FactoryMethod="Create">
  <x:Arguments><x:String>id</x:String></x:Arguments>
</Widget>
  <!-- but Widget.Create takes (int) -->
// after
<Widget x:FactoryMethod="FromId">
  <x:Arguments><x:String>id</x:String></x:Arguments>
</Widget>
Defensive patterns

Strategy: validation

Validate before calling

// Confirm a public static method with the given name/args exists
static bool HasStaticFactory(Type t, string name, Type[] argTypes) =>
    t.GetMethods(BindingFlags.Public | BindingFlags.Static)
     .Any(m => m.Name == name && m.GetParameters().Select(p => p.ParameterType).SequenceEqual(argTypes));

Prevention

When it happens

Trigger: Misspelling the factory method name; the method is an instance method (not static); argument signature mismatch; method was renamed/removed in a newer version; method is private/internal.

Common situations: Using a builder/factory pattern (e.g. MyType.Create(...)); refactoring renamed the factory; pointing x:FactoryMethod at an instance method by mistake.

Related errors


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