HangfireIO/Hangfire · error · InvalidOperationException

Could not get a value of the job parameter `{name}`. See inn

Error message

Could not get a value of the job parameter `{name}`. See inner exception for details.

What it means

Thrown by ApplyStateContext.GetJobParameter when reading or deserializing a job parameter fails. Identical mechanism to PerformContext.GetJobParameter: the value is missing, mismatches T, or the storage read throws. This context is available during state application (filters, state handlers). InnerException holds the root cause.

Source

Thrown at src/Hangfire.Core/States/ApplyStateContext.cs:122

            try
            {
                string value;

                if (allowStale && BackgroundJob.ParametersSnapshot != null)
                {
                    BackgroundJob.ParametersSnapshot.TryGetValue(name, out value);
                }
                else
                {
                    value = Connection.GetJobParameter(BackgroundJob.Id, name);                
                }

                return SerializationHelper.Deserialize<T>(value, SerializationOption.User);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(
                    $"Could not get a value of the job parameter `{name}`. See inner exception for details.", ex);
            }
        }
    }
}

View on GitHub (pinned to c236dd0f93)

Solutions

  1. Confirm the parameter is written before the state transition that reads it (e.g. set it in OnStateElection before ApplyState filters run).
  2. Match the generic type T to the type used when the parameter was stored.
  3. Guard the read with try/catch (InvalidOperationException) and use a sensible default for optional parameters.

Example fix

// before
var parentId = context.GetJobParameter<string>("ParentId"); // throws if unset

// after
string parentId;
try { parentId = context.GetJobParameter<string>("ParentId"); }
catch (InvalidOperationException) { parentId = null; }
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify the parameter was set before the transition reads it
var raw = context.Connection.GetJobParameter(context.BackgroundJob.Id, name);
if (string.IsNullOrEmpty(raw)) return default;

Try / catch

T value;
try { value = context.GetJobParameter<T>(name); }
catch (InvalidOperationException) { value = default; }

Prevention

When it happens

Trigger: Inside an IState/ElectState/ApplyState filter, calling context.GetJobParameter<T>(name) for a parameter that was never set, was set with an incompatible type, or whose storage read fails.

Common situations: A state filter reads a continuation or custom parameter that hasn't been written yet at that state-transition stage. Type mismatch between the setter (often in client code) and the filter's getter. Storage errors during the state-change transaction.

Related errors


AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13). Data as JSON: /api/errors/33040c522b2eb7f0. Report an issue: GitHub.