{"record":{"id":"709c80aa28f464a5","repo":"stride3d/stride","slug":"value-cannot-be-null-parameter-metadatas","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'metadatas')","messagePattern":"Value cannot be null\\. \\(Parameter 'metadatas'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.UI/DependencyPropertyFactory.cs","lineNumber":72,"sourceCode":"            return Register(name, ownerType, defaultValue, null, invalidationCallback);\n        }\n\n        /// <summary>\n        /// Registers a dependency property.\n        /// </summary>\n        /// <typeparam name=\"T\">The type of the property.</typeparam>\n        /// <param name=\"name\">The name of the property.</param>\n        /// <param name=\"ownerType\">The type that is registering the property.</param>\n        /// <param name=\"defaultValue\">The default value of the property.</param>\n        /// <param name=\"validateValueCallback\">A callback for validation/coercision of the property's value.</param>\n        /// <param name=\"invalidationCallback\">A callback to invalidate an object state after a modification of the property's value.</param>\n        /// <param name=\"metadatas\">The metadatas.</param>\n        /// <returns></returns>\n        public static PropertyKey<T> Register<T>(string name, Type ownerType, T defaultValue, ValidateValueCallback<T> validateValueCallback, ObjectInvalidationCallback<T> invalidationCallback, params PropertyKeyMetadata[] metadatas)\n        {\n            if (name == null) throw new ArgumentNullException(nameof(name));\n            if (ownerType == null) throw new ArgumentNullException(nameof(ownerType));\n            if (metadatas == null) throw new ArgumentNullException(nameof(metadatas));\n\n            return RegisterCommon(DependencyPropertyKeyMetadata.Default, name, ownerType, defaultValue, validateValueCallback, invalidationCallback, metadatas);\n        }\n\n        /// <summary>\n        /// Registers an attached dependency property.\n        /// </summary>\n        /// <typeparam name=\"T\">The type of the property.</typeparam>\n        /// <param name=\"name\">The name of the property.</param>\n        /// <param name=\"ownerType\">The type that is registering the property.</param>\n        /// <param name=\"defaultValue\">The default value of the property.</param>\n        /// <returns></returns>\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public static PropertyKey<T> RegisterAttached<T>(string name, Type ownerType, T defaultValue)\n        {\n            return RegisterAttached(name, ownerType, defaultValue, null, null);\n        }\n","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.UI/DependencyPropertyFactory.cs#L54-L90","documentation":"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.","triggerScenarios":"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.","commonSituations":"Reflection-driven property registration frameworks; generic wrappers around Register that pass their metadata parameter straight through when unset.","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"],"exampleFix":"// before\nDependencyPropertyFactory.Register(\"P\", typeof(C), 0, null, null, (PropertyKeyMetadata[])null); // throws\n// after\nDependencyPropertyFactory.Register(\"P\", typeof(C), 0, null, null); // no metadata args","handlingStrategy":"validation","validationCode":"metadatas ??= Array.Empty<PropertyKeyMetadata>();","typeGuard":"bool HasMetadata(PropertyKeyMetadata[] m) => m != null;","tryCatchPattern":"try\n{\n    key = DependencyPropertyFactory.Register(name, ownerType, defaultValue, null, null, metadatas);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"metadatas\")\n{\n    // supply an empty array or correct metadata\n}","preventionTips":["Rely on params and omit metadata instead of passing null","Coalesce null metadata arrays in wrappers","Prefer named arguments to make argument intent explicit"],"tags":["dependency-property","null-argument","ui"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}