{"record":{"id":"484e58e2ddfb5480","repo":"HangfireIO/Hangfire","slug":"multiple-provider-instances-registered-for-queues","errorCode":null,"errorMessage":"Multiple provider instances registered for queues: {String.Join(\", \", queues)}. You should choose only one type of persistent queues per server instance.","messagePattern":"Multiple provider instances registered for queues: (.+?)\\. You should choose only one type of persistent queues per server instance\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.SqlServer/SqlServerConnection.cs","lineNumber":81,"sourceCode":"\n        public override IDisposable AcquireDistributedLock([NotNull] string resource, TimeSpan timeout)\n        {\n            if (String.IsNullOrWhiteSpace(resource)) throw new ArgumentNullException(nameof(resource));\n            return AcquireLock($\"{_storage.SchemaName}:{resource}\", timeout);\n        }\n\n        public override IFetchedJob FetchNextJob(string[] queues, CancellationToken cancellationToken)\n        {\n            if (queues == null || queues.Length == 0) throw new ArgumentNullException(nameof(queues));\n\n            var providers = queues\n                .Select(queue => _storage.QueueProviders.GetProvider(queue))\n                .Distinct()\n                .ToArray();\n\n            if (providers.Length != 1)\n            {\n                throw new InvalidOperationException(\n                    $\"Multiple provider instances registered for queues: {String.Join(\", \", queues)}. You should choose only one type of persistent queues per server instance.\");\n            }\n            \n            var persistentQueue = providers[0].GetJobQueue();\n            return persistentQueue.Dequeue(queues, cancellationToken);\n        }\n\n        public override string CreateExpiredJob(\n            Job job,\n            IDictionary<string, string> parameters, \n            DateTime createdAt,\n            TimeSpan expireIn)\n        {\n            if (job == null) throw new ArgumentNullException(nameof(job));\n            if (parameters == null) throw new ArgumentNullException(nameof(parameters));\n\n            var queryString = _storage.GetQueryFromTemplate(static schemaName =>\n$@\"insert into [{schemaName}].Job (InvocationData, Arguments, CreatedAt, ExpireAt)","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.SqlServer/SqlServerConnection.cs#L63-L99","documentation":"InvalidOperationException thrown by SqlServerConnection.FetchNextJob when the queues requested map to more than one distinct IPersistentQueueProvider. A single Dequeue call must come from one provider; mixing providers (e.g. SQL Server native queues and MSMQ queues) in the same fetch list is rejected.","triggerScenarios":"Configuring a BackgroundJobServer (or calling FetchNextJob) with a queues array that spans providers registered in JobStorage.Current.QueueProviders — e.g. mixing \"default\" (Sql) with an MSMQ-backed queue name.","commonSituations":"Enabling UseMsmqQueues for some queues while keeping SQL queues and then listing both in BackgroundJobServerOptions.Queues; misconfiguring queue names so they resolve to different providers; running multiple server instances with overlapping but inconsistent queue sets.","solutions":["Give each BackgroundJobServer a queues array that resolves to exactly one provider, and split mixed workloads across separate server instances.","Review QueueProviders registrations and the queues array to ensure all entries map to the same provider.","If you migrated a queue from one provider to another, remove the old registration so names no longer collide."],"exampleFix":"// before\nvar options = new BackgroundJobServerOptions { Queues = new[] { \"default\", \"msmq-queue\" } };\n\n// after (one provider per server)\nvar sqlServer  = new BackgroundJobServer(new BackgroundJobServerOptions { Queues = new[] { \"default\" } });\nvar msmqServer = new BackgroundJobServer(new BackgroundJobServerOptions { Queues = new[] { \"msmq-queue\" } });","handlingStrategy":"validation","validationCode":"static string[] ResolveSingleProviderQueues(JobStorage storage, IEnumerable<string> queues)\n{\n    var providers = queues.Select(q => storage.QueueProviders.GetProvider(q)).Distinct().ToArray();\n    if (providers.Length != 1)\n        throw new InvalidOperationException(\n            \"Queues span multiple providers; split them across separate server instances.\");\n    return queues.ToArray();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run each BackgroundJobServer with queues from exactly one provider.","Audit QueueProviders registrations whenever you add MSMQ or other providers.","Add a startup check that all configured queues resolve to a single provider."],"tags":["sqlserver","queue","configuration"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}