dotnet/maui · error · ArgumentNullException

propertyName

Error message

propertyName

What it means

Argument null guard in the private BindableProperty constructor: propertyName must not be null. BindableProperty.Create forwards all of its arguments here, so any Create call (or CreateAttached/CreateReadOnly) that passes a null name hits this ArgumentNullException before any field is set.

Source

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

			{ typeof(char), new[] { typeof(string), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(decimal) } },
			{ typeof(float), new[] { typeof(string), typeof(double) } },
			{ typeof(ulong), new[] { typeof(string), typeof(float), typeof(double), typeof(decimal) } },
			{ typeof(double), new[] { typeof(string) } },
			{ 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)

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Pass a non-null propertyName (typically nameof(MyProperty)) to BindableProperty.Create.
  2. If the name comes from a computed string, validate it is non-null before the call.
  3. Add a unit test asserting the BindableProperty field is non-null after static initialization.

Example fix

// before
public static readonly BindableProperty TitleProperty =
    BindableProperty.Create(null, typeof(string), typeof(MyView));

// after
public static readonly BindableProperty TitleProperty =
    BindableProperty.Create(nameof(Title), typeof(string), typeof(MyView));
Defensive patterns

Strategy: validation

Validate before calling

if (propertyName is null) throw new ArgumentNullException(nameof(propertyName));
var bp = BindableProperty.Create(propertyName, typeof(string), typeof(MyView));

Type guard

static bool IsValidPropertyName(string name) => !string.IsNullOrWhiteSpace(name);

Prevention

When it happens

Trigger: Calling BindableProperty.Create(propertyName: null, ...) or CreateAttached(..., propertyName: null, ...); passing nameof() on a symbol that resolved to null in a refactor; dynamically building the name string and letting it be null.

Common situations: Refactoring a property and renaming it while the nameof() target was deleted; copy-paste between Create and CreateAttached that drops the name argument; code generation that emits a null name under some branch.

Related errors


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