{"record":{"id":"5d3c3b8e10e99cda","repo":"stride3d/stride","slug":"value-cannot-be-null-parameter-ownertype","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'ownerType')","messagePattern":"Value cannot be null\\. \\(Parameter 'ownerType'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.UI/DependencyPropertyFactory.cs","lineNumber":71,"sourceCode":"        {\n            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        }","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.UI/DependencyPropertyFactory.cs#L53-L89","documentation":"DependencyPropertyFactory.Register requires an owner Type for every dependency property; a null ownerType makes it impossible to scope the registered property key. The factory validates arguments up front and throws ArgumentNullException(nameof(ownerType)).","triggerScenarios":"Calling DependencyPropertyFactory.Register<T>(name, null, defaultValue, ...) with an uninitialized or generic-resolved owner type; a static field initializer running before the owner type constant is set; reflection-based registration where the owner type lookup returned null.","commonSituations":"Refactoring control classes and leaving a TypeOf/typeof expression null; dynamic plugin registration where the type is resolved from config; code generation output with a missing owner type argument.","solutions":["Pass the concrete owner type, e.g. typeof(MyControl), as the ownerType argument","If the type is resolved dynamically, check it for null before calling Register","Move registration into the owner class's static constructor so the type is certainly available"],"exampleFix":"// before\nvar key = DependencyPropertyFactory.Register(\"MyProp\", null, 0, null, null); // throws\n// after\nvar key = DependencyPropertyFactory.Register(\"MyProp\", typeof(MyControl), 0, null, null);","handlingStrategy":"validation","validationCode":"if (name == null || ownerType == null)\n    throw new ArgumentException(\"name and ownerType are required before Register\");","typeGuard":"bool CanRegister(string name, Type ownerType) => !string.IsNullOrEmpty(name) && ownerType != null;","tryCatchPattern":"try\n{\n    key = DependencyPropertyFactory.Register(name, ownerType, defaultValue, null, null);\n}\ncatch (ArgumentNullException ex)\n{\n    // log which argument was null; fix the registration site\n}","preventionTips":["Always pass typeof(DeclaringClass) literally","Register properties in the owner's static constructor","Null-check dynamically resolved types before calling the factory"],"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"}