dotnet/maui · error · ArgumentException

Unhandled binding type '{0}'

Error message

Unhandled binding type '{0}'

What it means

WindowsExpressionSearch.VisitBinding throws ArgumentException for MemberBinding types not handled in its switch. Only Assignment, MemberBinding (nested), and ListBinding are handled. Any other MemberBindingType value triggers the exception.

Source

Thrown at src/Compatibility/Core/src/Windows/WindowsExpressionSearch.cs:137

					throw new ArgumentException(string.Format("Unhandled expression type: '{0}'", expression.NodeType));
			}
		}

		void VisitBinding(MemberBinding binding)
		{
			switch (binding.BindingType)
			{
				case MemberBindingType.Assignment:
					Visit(((MemberAssignment)binding).Expression);
					break;
				case MemberBindingType.MemberBinding:
					VisitList(((MemberMemberBinding)binding).Bindings, VisitBinding);
					break;
				case MemberBindingType.ListBinding:
					VisitList(((MemberListBinding)binding).Initializers, initializer => VisitList(initializer.Arguments, Visit));
					break;
				default:
					throw new ArgumentException(string.Format("Unhandled binding type '{0}'", binding.BindingType));
			}
		}

		static void VisitList<TList>(IEnumerable<TList> list, Action<TList> visitor)
		{
			foreach (TList element in list)
			{
				visitor(element);
			}
		}

		// All important magic happens here
		void VisitMemberAccess(MemberExpression member)
		{
			if (member.Expression is ConstantExpression && member.Member is FieldInfo)
			{
				object container = ((ConstantExpression)member.Expression).Value;
				object value = ((FieldInfo)member.Member).GetValue(container);

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Simplify binding expressions to avoid member initialization constructs
  2. Pre-construct objects in the ViewModel rather than in binding expressions
  3. Use simpler property-access-only binding paths

Example fix

// before — member init with unsupported binding type
SetBinding(ItemProperty, new Binding(() => new Item { Name = name }));

// after — bind to pre-constructed property
SetBinding(ItemProperty, new Binding(nameof(ViewModel.PreBuiltItem)));
Defensive patterns

Strategy: try-catch

Validate before calling

// Before using member initialization in bindings, verify binding types are supported
static bool HasSupportedBindings(MemberInitExpression init)
{
    return init.Bindings.All(b =>
        b.BindingType == MemberBindingType.Assignment
        || b.BindingType == MemberBindingType.MemberBinding
        || b.BindingType == MemberBindingType.ListBinding);
}

Try / catch

try
{
    SetBinding(MyProperty, new Binding(() => new Item { Name = name }));
}
catch (ArgumentException ex) when (ex.Message.Contains("Unhandled binding type"))
{
    // Fall back to pre-constructed object binding
    SetBinding(MyProperty, new Binding(nameof(ViewModel.PreBuiltItem)));
}

Prevention

When it happens

Trigger: An expression tree with member initialization containing an unsupported binding type passed through the expression search. This occurs when data bindings reference complex member initialization expressions.

Common situations: Complex object initialization in binding expressions; lambda-based bindings that construct new objects with member initializers; expression-based binding definitions with unusual shapes.

Related errors


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