dotnet/maui · error · ArgumentNullException

declaringType

Error message

declaringType

What it means

Argument null guard in the private BindableProperty constructor: declaringType must not be null. declaringType identifies the owner type of the property (used for attached properties and lookup), so null makes registration impossible. Reached via BindableProperty.Create / CreateAttached.

Source

Thrown at src/Controls/src/Core/BindableProperty.cs:197

			{ typeof(bool), new[] { typeof(string) } },
		};

		/// <summary>A sentinel object used to indicate that a BindableProperty value has not been set.</summary>
		public static readonly object UnsetValue = new object();

		private static int _nextInternalId = int.MinValue;
		internal readonly int InternalId;

		BindableProperty(string propertyName, [DynamicallyAccessedMembers(ReturnTypeMembers)] Type returnType, [DynamicallyAccessedMembers(DeclaringTypeMembers)] Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay,
								 ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null,
								 CoerceValueDelegate coerceValue = null, BindablePropertyBindingChanging bindingChanging = null, bool isReadOnly = false, CreateDefaultValueDelegate defaultValueCreator = null)
		{
			if (propertyName == null)
				throw new ArgumentNullException(nameof(propertyName));
			if (returnType is null)
				throw new ArgumentNullException(nameof(returnType));
			if (declaringType is null)
				throw new ArgumentNullException(nameof(declaringType));
			
			InternalId = Interlocked.Increment(ref _nextInternalId);

			// don't use Enum.IsDefined as its redonkulously expensive for what it does
			if (defaultBindingMode != BindingMode.Default && defaultBindingMode != BindingMode.OneWay && defaultBindingMode != BindingMode.OneWayToSource && defaultBindingMode != BindingMode.TwoWay && defaultBindingMode != BindingMode.OneTime)
				throw new ArgumentException($"Not a valid type of BindingMode. Property: {returnType} {declaringType.Name}.{propertyName}. Default binding mode: {defaultBindingMode}", nameof(defaultBindingMode));

			if (defaultValue == null && Nullable.GetUnderlyingType(returnType) == null && returnType.IsValueType)
				defaultValue = Activator.CreateInstance(returnType);

			if (defaultValue != null && !returnType.IsInstanceOfType(defaultValue))
				throw new ArgumentException($"Default value did not match return type. Property: {returnType} {declaringType.Name}.{propertyName} Default value type: {defaultValue.GetType().Name}, ", nameof(defaultValue));

			if (defaultBindingMode == BindingMode.Default)
				defaultBindingMode = BindingMode.OneWay;

			PropertyName = propertyName;
			ReturnType = returnType;

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Pass the declaring type, typically typeof(MyControl), as the third argument.
  2. For attached properties use BindableProperty.CreateAttached with a concrete owner type.
  3. Ensure the owner type assembly is referenced on every target framework.

Example fix

// before
public static readonly BindableProperty ColumnProperty =
    BindableProperty.CreateAttached(nameof(GetColumn), typeof(int), null, 0);

// after
public static readonly BindableProperty ColumnProperty =
    BindableProperty.CreateAttached(nameof(GetColumn), typeof(int), typeof(MyGrid), 0);
Defensive patterns

Strategy: validation

Validate before calling

if (declaringType is null) throw new ArgumentNullException(nameof(declaringType));
var bp = BindableProperty.CreateAttached(nameof(GetCol), typeof(int), declaringType, 0);

Prevention

When it happens

Trigger: BindableProperty.Create(nameof(X), typeof(int), null); CreateAttached with a null owner type; passing a typeof() on a type that was removed from the assembly.

Common situations: Defining an attached property in a class whose typeof() reference broke during a rename; multi-targeting where the owner type lives in a platform-specific assembly not referenced on the active target.

Related errors


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