stride3d/stride · error · ArgumentNullException

Value cannot be null. (Parameter 'name')

Error message

Value cannot be null. (Parameter 'name')

What it means

RegisterAttached registers an attached dependency property, which must be scoped to a name and owner type. A null name leaves the property unidentifiable, so the factory throws ArgumentNullException(nameof(name)) as its first validation.

Solutions

  1. Pass a non-null property name string to RegisterAttached
  2. Validate names loaded from config/reflection before calling the factory
  3. Fail fast earlier with a clear message if a name cannot be resolved

Example fix

// before
var key = DependencyPropertyFactory.RegisterAttached<string>(null, typeof(Grid), default); // throws
// after
var key = DependencyPropertyFactory.RegisterAttached<string>("MyAttachedProp", typeof(Grid), default);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(name))
    throw new ArgumentException("Attached property name is required");

Type guard

bool CanRegisterAttached(string name, Type ownerType) => !string.IsNullOrEmpty(name) && ownerType != null;

Try / catch

try
{
    key = DependencyPropertyFactory.RegisterAttached<T>(name, ownerType, default);
}
catch (ArgumentNullException ex) when (ex.ParamName == "name")
{
    // fix the name source before retrying
}

Prevention

When it happens

Trigger: Calling DependencyPropertyFactory.RegisterAttached<T>(null, ownerType, ...) with a null/empty property name, e.g. from a config-driven or reflection-based registration where the name lookup failed.

Common situations: Dynamic registration systems that read property names from configuration or attributes; code generation with a missing name constant; refactoring where the name literal was accidentally deleted.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/88bc0c829fac8943. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.UI/DependencyPropertyFactory.cs:134

        public static PropertyKey<T> RegisterAttached<T>(string name, Type ownerType, T defaultValue, ObjectInvalidationCallback<T> invalidationCallback)
        {
            return RegisterAttached(name, ownerType, defaultValue, null, invalidationCallback);
        }

        /// <summary>
        /// Registers an attached dependency property.
        /// </summary>
        /// <typeparam name="T">The type of the property.</typeparam>
        /// <param name="name">The name of the property.</param>
        /// <param name="ownerType">The type that is registering the property.</param>
        /// <param name="defaultValue">The default value of the property.</param>
        /// <param name="validateValueCallback">A callback for validation/coercision of the property's value.</param>
        /// <param name="invalidationCallback">A callback to invalidate an object state after a modification of the property's value.</param>
        /// <param name="metadatas">The metadatas.</param>
        /// <returns></returns>
        public static PropertyKey<T> RegisterAttached<T>(string name, Type ownerType, T defaultValue, ValidateValueCallback<T> validateValueCallback, ObjectInvalidationCallback<T> invalidationCallback, params PropertyKeyMetadata[] metadatas)
        {
            if (name == null) throw new ArgumentNullException(nameof(name));
            if (ownerType == null) throw new ArgumentNullException(nameof(ownerType));
            if (metadatas == null) throw new ArgumentNullException(nameof(metadatas));

            return RegisterCommon(DependencyPropertyKeyMetadata.Attached, name, ownerType, defaultValue, validateValueCallback, invalidationCallback, metadatas);
        }

        // ReSharper disable once SuggestBaseTypeForParameter
        private static PropertyKey<T> RegisterCommon<T>(DependencyPropertyKeyMetadata dependencyPropertyMetadata, string name, Type ownerType, T defaultValue, ValidateValueCallback<T> validateValueCallback, ObjectInvalidationCallback<T> invalidationCallback, params PropertyKeyMetadata[] otherMetadatas)
        {
            var metadataList = new List<PropertyKeyMetadata> { dependencyPropertyMetadata, DefaultValueMetadata.Static(defaultValue) };
            if (validateValueCallback != null)
                metadataList.Add(ValidateValueMetadata.New(validateValueCallback));
            if (invalidationCallback != null)
                metadataList.Add(ObjectInvalidationMetadata.New(invalidationCallback));
            metadataList.AddRange(otherMetadatas);

            return new PropertyKey<T>(name, ownerType, metadataList.ToArray());
        }

View on GitHub (pinned to 96fad776d2)