stride3d/stride · error · ArgumentNullException
Value cannot be null. (Parameter 'metadatas')
Error message
Value cannot be null. (Parameter 'metadatas')
What it means
The metadatas parameter of DependencyPropertyFactory.Register is declared as a params array but is still explicitly null-checked; passing an explicit null array is treated as a programming mistake. The factory throws ArgumentNullException(nameof(metadatas)) before registering the property.
Solutions
- Omit the metadata arguments entirely (params allows zero arguments) instead of passing null
- Pass an empty array: Array.Empty<PropertyKeyMetadata>()
- In wrappers, default null metadata lists to an empty array before forwarding
Example fix
// before
DependencyPropertyFactory.Register("P", typeof(C), 0, null, null, (PropertyKeyMetadata[])null); // throws
// after
DependencyPropertyFactory.Register("P", typeof(C), 0, null, null); // no metadata args Defensive patterns
Strategy: validation
Validate before calling
metadatas ??= Array.Empty<PropertyKeyMetadata>();
Type guard
bool HasMetadata(PropertyKeyMetadata[] m) => m != null;
Try / catch
try
{
key = DependencyPropertyFactory.Register(name, ownerType, defaultValue, null, null, metadatas);
}
catch (ArgumentNullException ex) when (ex.ParamName == "metadatas")
{
// supply an empty array or correct metadata
} Prevention
- Rely on params and omit metadata instead of passing null
- Coalesce null metadata arrays in wrappers
- Prefer named arguments to make argument intent explicit
When it happens
Trigger: Calling Register<T>(...) with an explicitly cast null: metadatas: (PropertyKeyMetadata[])null; invoking the method via reflection or a delegate that supplies a null array; an overload shim forwarding a null metadata list.
Common situations: Reflection-driven property registration frameworks; generic wrappers around Register that pass their metadata parameter straight through when unset.
Related errors
- Value cannot be null. (Parameter 'ownerType')
- Title can not be null
- texture
- font
- Value cannot be null. (Parameter 'name')
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/709c80aa28f464a5.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.UI/DependencyPropertyFactory.cs:72
return Register(name, ownerType, defaultValue, null, invalidationCallback);
}
/// <summary>
/// Registers a 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> Register<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.Default, name, ownerType, defaultValue, validateValueCallback, invalidationCallback, metadatas);
}
/// <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>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static PropertyKey<T> RegisterAttached<T>(string name, Type ownerType, T defaultValue)
{
return RegisterAttached(name, ownerType, defaultValue, null, null);
}
View on GitHub (pinned to 96fad776d2)