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 ElectStateContext.GetJobParameter when reading or deserializing a job parameter fails. Same pattern as PerformContext and ApplyStateContext: missing value, type mismatch, or storage read failure, wrapped with the root cause as InnerException. This context is active during state election (before a state is applied).

Source

Thrown at src/Hangfire.Core/States/ElectStateContext.cs:128

            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. Ensure the parameter is set (SetJobParameter) at enqueue time, before any election filter reads it.
  2. Use the exact type T that was used to store the parameter.
  3. Catch InvalidOperationException around the read and apply a default for optional parameters.

Example fix

// before
var count = context.GetJobParameter<int>("Attempts"); // throws if unset

// after
int count;
try { count = context.GetJobParameter<int>("Attempts"); }
catch (InvalidOperationException) { count = 0; }
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure parameters read during election were written at enqueue time
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 filter's OnStateElection or an IElectStateFilter, calling context.GetJobParameter<T>(name) for a parameter not yet present, stored with a different type, or unreadable from storage.

Common situations: A continuation or retry filter reads a parameter during election that the client hasn't written. Generic type mismatch between writer and reader. Storage connectivity issue during election.

Related errors


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