{"record":{"id":"7bee91a1c21396ae","repo":"HangfireIO/Hangfire","slug":"connectionfactory","errorCode":null,"errorMessage":"connectionFactory","messagePattern":"connectionFactory","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.SqlServer/SqlServerStorage.cs","lineNumber":143,"sourceCode":"\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"SqlServerStorage\"/> class with\n        /// a connection factory <see cref=\"Func{DbConnection}\"/> class that will be invoked\n        /// to create new database connections for querying the data.\n        /// </summary>\n        public SqlServerStorage([NotNull] Func<DbConnection> connectionFactory)\n            : this(connectionFactory, new SqlServerStorageOptions())\n        {\n        }\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"SqlServerStorage\"/> class with\n        /// a connection factory <see cref=\"Func{DbConnection}\"/> class that will be invoked\n        /// to create new database connections for querying the data.\n        /// </summary>\n        public SqlServerStorage([NotNull] Func<DbConnection> connectionFactory, [NotNull] SqlServerStorageOptions options)\n        {\n            if (connectionFactory == null) throw new ArgumentNullException(nameof(connectionFactory));\n            if (options == null) throw new ArgumentNullException(nameof(options));\n\n            _connectionFactory = connectionFactory;\n            _options = options;\n\n            Initialize();\n        }\n\n        public virtual PersistentJobQueueProviderCollection QueueProviders { get; private set; }\n\n        public override bool LinearizableReads => true;\n\n        internal string SchemaName => _escapedSchemaName;\n        internal int? CommandTimeout => _options.CommandTimeout.HasValue ? (int)_options.CommandTimeout.Value.TotalSeconds : (int?)null;\n        internal int? CommandBatchMaxTimeout => _options.CommandBatchMaxTimeout.HasValue ? (int)_options.CommandBatchMaxTimeout.Value.TotalSeconds : (int?)null;\n        internal TimeSpan? SlidingInvisibilityTimeout => _options.SlidingInvisibilityTimeout;\n        internal SqlServerStorageOptions Options => _options;\n        internal SqlServerHeartbeatProcess HeartbeatProcess => _heartbeatProcess;","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.SqlServer/SqlServerStorage.cs#L125-L161","documentation":"The SqlServerStorage constructor received a null connectionFactory argument (a Func<DbConnection>). This is a standard ArgumentNullException guard at the top of the (Func<DbConnection>, SqlServerStorageOptions) constructor.","triggerScenarios":"Passing null to new SqlServerStorage(connectionFactory, options); a factory variable that was never assigned.","commonSituations":"DI misconfiguration where the factory delegate resolves to null; refactoring that removes the factory assignment; conditional code paths that skip factory initialization.","solutions":["Provide a non-null Func<DbConnection> that returns a new, unopened DbConnection each invocation.","If the factory comes from DI, ensure it is registered and resolvable.","Validate with a null check before construction."],"exampleFix":"// before\nFunc<DbConnection> factory = null; // not initialized\nvar storage = new SqlServerStorage(factory, options);\n// after\nFunc<DbConnection> factory = () => new SqlConnection(connectionString);\nvar storage = new SqlServerStorage(factory, options);","handlingStrategy":"validation","validationCode":"Func<DbConnection> connectionFactory = /* assignment */;\nif (connectionFactory == null)\n    throw new InvalidOperationException(\"connectionFactory delegate must be provided.\");\n\nvar storage = new SqlServerStorage(connectionFactory, options);","typeGuard":"static bool IsValidFactory(Func<DbConnection> factory) => factory != null;","tryCatchPattern":null,"preventionTips":["Always initialize the factory delegate before passing it to SqlServerStorage.","Register the factory in DI if using dependency injection.","Ensure the factory returns a fresh, unopened DbConnection each invocation."],"tags":["argument-null","constructor","connection-factory","validation"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}