{"record":{"id":"e8132f748f4876a6","repo":"stride3d/stride","slug":"factory","errorCode":null,"errorMessage":"factory","messagePattern":"factory","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Serialization/LambdaObjectFactory.cs","lineNumber":75,"sourceCode":"        /// <summary>\n        /// Initializes a new instance of the <see cref=\"LambdaObjectFactory\"/> class.\n        /// </summary>\n        /// <param name=\"factory\">The factory.</param>\n        public LambdaObjectFactory(Func<Type, object> factory) : this(factory, null)\n        {\n        }\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"LambdaObjectFactory\" /> class.\n        /// </summary>\n        /// <param name=\"factory\">The factory.</param>\n        /// <param name=\"nextFactory\">The next factory.</param>\n        /// <exception cref=\"System.ArgumentNullException\">factory</exception>\n        public LambdaObjectFactory(Func<Type, object> factory, IObjectFactory nextFactory) : base(nextFactory)\n        {\n            if (factory == null)\n            {\n                throw new ArgumentNullException(\"factory\");\n            }\n\n            this.factory = factory;\n        }\n\n        public override object Create(Type type)\n        {\n            return factory(type) ?? base.Create(type);\n        }\n    }\n}","sourceCodeStart":57,"sourceCodeEnd":86,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Serialization/LambdaObjectFactory.cs#L57-L86","documentation":"LambdaObjectFactory's second constructor validates its Func<Type,object> delegate argument and throws ArgumentNullException named \"factory\" when it is null. This guard exists because the factory cannot fall back to a null delegate at Create time.","triggerScenarios":"new LambdaObjectFactory(null, nextFactory) — passing a null factory delegate, typically when the delegate is produced by an expression that returned null or an uninitialized field.","commonSituations":"Conditional factory setup where a lambda variable is assigned only in some branches; reflection-driven configuration that failed to resolve the factory delegate.","solutions":["Pass a non-null delegate when constructing LambdaObjectFactory","Check the factory delegate for null before constructing and fail fast with a clearer message","Use the nameof-safe overload pattern at your call site to catch the bug early in tests","If the delegate may legitimately be absent, skip registering this factory instead of passing null"],"exampleFix":"// before\nnew LambdaObjectFactory(null, nextFactory)\n// after\nFunc<Type, object> factory = t => Activator.CreateInstance(t);\nnew LambdaObjectFactory(factory, nextFactory)","handlingStrategy":"type-guard","validationCode":"if (factory is null) throw new ArgumentNullException(nameof(factory));","typeGuard":"static bool IsValidFactory(Func<Type, object> f) => f != null;","tryCatchPattern":"try { var f = new LambdaObjectFactory(factory, nextFactory); }\ncatch (ArgumentNullException ex) { throw new InvalidOperationException(\"Factory delegate must be provided\", ex); }","preventionTips":["Never allow factory delegates to be assigned conditionally without defaults","Use nameof in ArgumentNullExceptions at your own boundaries","Cover factory wiring with constructor tests","Treat nullable Func fields as bugs; initialize eagerly"],"tags":["argument-null","factory","csharp"],"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"}