{"record":{"id":"29bb8c8958b8d9d6","repo":"HangfireIO/Hangfire","slug":"background-job-creation-failed-see-inner-exceptio","errorCode":null,"errorMessage":"Background job creation failed. See inner exception for details.","messagePattern":"Background job creation failed\\. See inner exception for details\\.","errorType":"exception","errorClass":"BackgroundJobClientException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/BackgroundJobClient.cs","lineNumber":163,"sourceCode":"        /// <inheritdoc />\n        public string Create(Job job, IState state, IDictionary<string, object> parameters)\n        {\n            if (job == null) throw new ArgumentNullException(nameof(job));\n            if (state == null) throw new ArgumentNullException(nameof(state));\n\n            try\n            {\n                using (var connection = _storage.GetConnection())\n                {\n                    var context = new CreateContext(_storage, connection, job, state, parameters);\n                    var backgroundJob = _factory.Create(context);\n\n                    return backgroundJob?.Id;\n                }\n            }\n            catch (Exception ex) when (ex.IsCatchableExceptionType())\n            {\n                throw new BackgroundJobClientException(\"Background job creation failed. See inner exception for details.\", ex);\n            }\n        }\n\n        /// <inheritdoc />\n        public bool ChangeState(string jobId, IState state, string expectedState)\n        {\n            if (jobId == null) throw new ArgumentNullException(nameof(jobId));\n            if (state == null) throw new ArgumentNullException(nameof(state));\n\n            try\n            {\n                using (var connection = _storage.GetConnection())\n                {\n                    var appliedState = _stateChanger.ChangeState(new StateChangeContext(\n                        _storage,\n                        connection,\n                        jobId,\n                        state,","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/BackgroundJobClient.cs#L145-L181","documentation":"BackgroundJobClient.Create wraps any catchable (non-StackOverflow/non-OutOfMemory style) exception thrown during job creation — opening a storage connection, building the CreateContext, or invoking the IBackgroundJobFactory — into a BackgroundJobClientException with the original error as InnerException. The message is generic because the real cause is in InnerException; always inspect it. This preserves a single exception contract for callers regardless of the underlying storage or serialization failure.","triggerScenarios":"Calling client.Create(job, state) when JobStorage.GetConnection() throws (DB unreachable, Redis down), when the job arguments fail serialization, when a custom IBackgroundJobFactory throws, or when the IState implementation is malformed.","commonSituations":"Database/Redis connection string wrong or network partition during enqueue; serializing a non-serializable argument (closures, IDisposable); storage schema migration pending; custom factory or state filter that throws.","solutions":["Read the InnerException (and its type) to identify the real failure — connection, serialization, or factory logic.","For storage errors: verify the JobStorage connection string and that the storage backend is reachable.","For serialization errors: ensure job arguments are simple, serializable types; avoid closures and complex object graphs.","Wrap the Create call in try/catch(BackgroundJobClientException) and handle/retry/log appropriately."],"exampleFix":"// before\nvar id = client.Create(job, state);\n\n// after\ntry\n{\n    var id = client.Create(job, state);\n}\ncatch (BackgroundJobClientException ex)\n{\n    logger.Error(ex.InnerException, \"Job creation failed\");\n    throw;\n}","handlingStrategy":"try-catch","validationCode":"// Pre-check connectivity (best-effort) before creating a job\nif (JobStorage.Current == null) throw new InvalidOperationException(\"JobStorage not configured\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var id = client.Create(job, state);\n}\ncatch (BackgroundJobClientException ex)\n{\n    logger.Error(ex.InnerException, \"Job creation failed\");\n    // retry, queue for later, or surface to caller\n}","preventionTips":["Always inspect InnerException — it carries the real cause.","Ensure job arguments are simple serializable types.","Validate storage connectivity at startup before enqueueing."],"tags":["storage","serialization","job-creation","backgroundjobclientexception","wrapper"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}