{"record":{"id":"a5592a57988525d9","repo":"HangfireIO/Hangfire","slug":"could-not-set-parameter-for-a-created-job","errorCode":null,"errorMessage":"Could not set parameter for a created job.","messagePattern":"Could not set parameter for a created job\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/Client/CreatedContext.cs","lineNumber":73,"sourceCode":"\n        /// <summary>\n        /// Gets a value that indicates that this <see cref=\"CreatedContext\"/>\n        /// object was canceled.\n        /// </summary>\n        public bool Canceled { get; }\n\n        /// <summary>\n        /// Gets or sets a value that indicates that this <see cref=\"CreatedContext\"/>\n        /// object handles an exception occurred during the creation of the job.\n        /// </summary>\n        public bool ExceptionHandled { get; set; }\n\n        [Obsolete(\"This method only throws InvalidOperationException, will be removed in 2.0.0.\")]\n        public void SetJobParameter([NotNull] string name, object value)\n        {\n            if (String.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name));\n\n            throw new InvalidOperationException(\"Could not set parameter for a created job.\");\n        }\n    }\n}","sourceCodeStart":55,"sourceCodeEnd":76,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/Client/CreatedContext.cs#L55-L76","documentation":"InvalidOperationException thrown unconditionally by CreatedContext.SetJobParameter, which is marked [Obsolete] and documented to only throw. After a job is created (OnCreated phase), parameters can no longer be set — the job is already persisted with its serialized parameters. This stub exists for backward API compatibility and will be removed in 2.0.0. Calling it is always an error; use CreatingContext.SetJobParameter during the OnCreating phase instead.","triggerScenarios":"Calling createdContext.SetJobParameter(\"key\", value) inside an IClientFilter.OnCreated handler or any code holding a CreatedContext. Also triggered by migrating old code that called SetJobParameter on the post-creation context.","commonSituations":"Legacy filters written against an older API that allowed parameter mutation after creation; copy-paste from OnCreating logic into OnCreated; filters that try to stamp metadata onto the job after it is already stored.","solutions":["Move SetJobParameter calls into the OnCreating phase, using CreatingContext.SetJobParameter.","If the data must be attached after creation, store it in context.Items (in-process only) or write a separate job parameter via a storage transaction.","Delete calls to CreatedContext.SetJobParameter entirely — it never succeeds."],"exampleFix":"// before (OnCreated — always throws)\npublic void OnCreated(CreatedContext context) {\n    context.SetJobParameter(\"Tag\", \"value\");\n}\n\n// after (OnCreating — correct phase)\npublic void OnCreating(CreatingContext context) {\n    context.SetJobParameter(\"Tag\", \"value\");\n}","handlingStrategy":"validation","validationCode":"// Never call CreatedContext.SetJobParameter — it always throws.\n// Move all SetJobParameter calls to OnCreating where CreatingContext.SetJobParameter works.","typeGuard":null,"tryCatchPattern":"try { createdContext.SetJobParameter(\"k\", v); }\ncatch (InvalidOperationException) { /* migrate to OnCreating */ }","preventionTips":["Set parameters only in the OnCreating phase (CreatingContext), never in OnCreated.","Run the obsolete-warnings compiler check — CreatedContext.SetJobParameter is [Obsolete].","For post-creation metadata, use context.Items or a separate storage write."],"tags":["obsolete","job-parameter","client-filter","api-misuse"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}