dotnet/maui · error · BuildException

XC0005

XC0005

Error message

Missing constructor for "{0}" with matching x:Arguments.

What it means

Thrown by CreateObjectVisitor when an element declares x:Arguments but no accessible instance constructor on the type matches those argument types (MatchXArguments failed for every candidate). The compiler needs a concrete constructor to emit the newobj call.

Source

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

					if (!node.SkipProperties.Contains(prop.Key))
						node.SkipProperties.Add(prop.Key);
				node.CollectionItems.Clear();

				return;
			}

			MethodDefinition factoryCtorInfo = null;
			MethodDefinition factoryMethodInfo = null;
			MethodDefinition parameterizedCtorInfo = null;
			MethodDefinition ctorInfo = null;

			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 &&

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Inspect the type's public constructors and align x:Arguments element types/count to one of them.
  2. Use the correct x:Int/x:Double/x:String wrapper elements so argument types match.
  3. If the matching ctor is non-public, make it public or add InternalsVisibleTo.
  4. If no ctor fits, add a parameterized factory and use x:FactoryMethod instead.

Example fix

// before
<Size>
  <x:Arguments>
    <x:String>10</x:String>
    <x:String>20</x:String>
  </x:Arguments>
</Size>
// after
<Size>
  <x:Arguments>
    <x:Double>10</x:Double>
    <x:Double>20</x:Double>
  </x:Arguments>
</Size>
Defensive patterns

Strategy: validation

Validate before calling

// Verify a constructor matches the x:Arguments you intend to supply
static bool HasMatchingCtor(Type t, Type[] argTypes) =>
    t.GetConstructors().Any(c => c.GetParameters()
        .Select(p => p.ParameterType).SequenceEqual(argTypes));

Prevention

When it happens

Trigger: Listing x:Arguments whose types/signature do not match any constructor; constructor is internal/private; using a generic type whose ctor needs type-arg resolution; argument types are wrong (e.g. x:Int where a double ctor is expected).

Common situations: Calling a struct/value-type ctor with wrong arg count; passing a string where a typed converter would be needed at runtime but not at compile time; mismatched overload after a package update changed available constructors.

Related errors


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