{"record":{"id":"03f424ef6d897826","repo":"HangfireIO/Hangfire","slug":"connectionfactory-03f424","errorCode":null,"errorMessage":"connectionFactory","messagePattern":"connectionFactory","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.SqlServer/SqlServerStorageExtensions.cs","lineNumber":70,"sourceCode":"\n        public static IGlobalConfiguration<SqlServerStorage> UseSqlServerStorage(\n            [NotNull] this IGlobalConfiguration configuration,\n            [NotNull] Func<DbConnection> connectionFactory)\n        {\n            if (configuration == null) throw new ArgumentNullException(nameof(configuration));\n            if (connectionFactory == null) throw new ArgumentNullException(nameof(connectionFactory));\n\n            var storage = new SqlServerStorage(connectionFactory);\n            return configuration.UseStorage(storage).UseSqlServerStorageCommonMetrics();\n        }\n\n        public static IGlobalConfiguration<SqlServerStorage> UseSqlServerStorage(\n            [NotNull] this IGlobalConfiguration configuration,\n            [NotNull] Func<DbConnection> connectionFactory,\n            [NotNull] SqlServerStorageOptions options)\n        {\n            if (configuration == null) throw new ArgumentNullException(nameof(configuration));\n            if (connectionFactory == null) throw new ArgumentNullException(nameof(connectionFactory));\n            if (options == null) throw new ArgumentNullException(nameof(options));\n\n            var storage = new SqlServerStorage(connectionFactory, options);\n            return configuration.UseStorage(storage).UseSqlServerStorageCommonMetrics();\n        }\n\n        private static IGlobalConfiguration<SqlServerStorage> UseSqlServerStorageCommonMetrics(\n            [NotNull] this IGlobalConfiguration<SqlServerStorage> configuration)\n        {\n            if (configuration == null) throw new ArgumentNullException(nameof(configuration));\n\n            if (Interlocked.Exchange(ref _metricsInitialized, 1) == 0)\n            {\n                configuration.UseDashboardMetric(SqlServerStorage.SchemaVersion);\n                configuration.UseDashboardMetric(SqlServerStorage.ActiveConnections);\n                configuration.UseDashboardMetric(SqlServerStorage.TotalConnections);\n                configuration.UseDashboardMetric(SqlServerStorage.ActiveTransactions);\n                configuration.UseDashboardMetric(SqlServerStorage.DataFilesSize);","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.SqlServer/SqlServerStorageExtensions.cs#L52-L88","documentation":"The UseSqlServerStorage(this IGlobalConfiguration, Func<DbConnection>, SqlServerStorageOptions) extension method received a null connectionFactory argument. This is a standard ArgumentNullException guard for the factory delegate parameter.","triggerScenarios":"Passing null as the Func<DbConnection> to the three-parameter UseSqlServerStorage overload; a factory that was never assigned.","commonSituations":"DI misconfiguration; uninitialized variable; refactoring that removes the factory creation.","solutions":["Provide a non-null Func<DbConnection> that creates a fresh, unopened DbConnection.","Validate the factory is non-null before calling."],"exampleFix":"// before\nFunc<DbConnection> factory = null;\nconfig.UseSqlServerStorage(factory, options);\n// after\nFunc<DbConnection> factory = () => new SqlConnection(connStr);\nconfig.UseSqlServerStorage(factory, options);","handlingStrategy":"validation","validationCode":"Func<DbConnection> connectionFactory = () => new SqlConnection(connStr);\nif (connectionFactory == null)\n    throw new InvalidOperationException(\"connectionFactory must be provided.\");\n\nconfig.UseSqlServerStorage(connectionFactory, options);","typeGuard":"static bool IsValidFactory(Func<DbConnection> factory) => factory != null;","tryCatchPattern":null,"preventionTips":["Initialize the factory delegate before calling UseSqlServerStorage.","Register the factory in DI if using dependency injection.","Ensure the factory returns a fresh, unopened DbConnection each invocation."],"tags":["argument-null","extension-method","connection-factory","setup"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}