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
InvalidOperationException thrown by CreatingContext.GetJobParameter<T> when an existing parameter value cannot be cast to type T. The method looks up the parameter by name in the in-memory Parameters dictionary and attempts a direct cast (T)parameter; on InvalidCastException (or other cast-time exceptions filtered through IsCatchableExceptionType) it wraps the original as an inner exception. This typically means a parameter was stored with a different runtime type than requested, or the caller requested the wrong generic type.
Source
Thrown at src/Hangfire.Core/Client/CreatingContext.cs:77
/// <typeparam name="T">The type of the parameter.</typeparam>
/// <param name="name">The name of the parameter.</param>
/// <returns>The value of the given parameter if it exists or null otherwise.</returns>
///
/// <exception cref="ArgumentNullException">The <paramref name="name"/> is null or empty.</exception>
/// <exception cref="InvalidOperationException">Could not deserialize the parameter value to the type <typeparamref name="T"/>.</exception>
public T GetJobParameter<T>(string name)
{
if (String.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name));
try
{
return Parameters.TryGetValue(name, out var parameter)
? (T)parameter
: default(T);
}
catch (Exception ex) when (ex.IsCatchableExceptionType())
{
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
- Match the generic type to the type used when SetJobParameter was called — Hangfire stores CurrentCulture as string, so use GetJobParameter<string>("CurrentCulture").
- Inspect the Parameters dictionary (or context.Items) before casting to verify the runtime type.
- Coordinate type contracts between the writing filter (OnCreating) and reading filter (OnPerforming) with a shared helper or constant.
Example fix
// before — type mismatch
var culture = context.GetJobParameter<CultureInfo>("CurrentCulture");
// after — Hangfire stores it as a string name
var cultureName = context.GetJobParameter<string>("CurrentCulture");
var culture = cultureName != null ? CultureInfo.GetCultureInfo(cultureName) : CultureInfo.CurrentCulture; Defensive patterns
Strategy: try-catch
Validate before calling
var raw = context.Parameters.TryGetValue(name, out var p) ? p : null; if (raw != null && raw is T typed) return typed; // else handle type mismatch before calling GetJobParameter<T>
Type guard
public static bool CanGetAs<T>(CreatingContext ctx, string name)
=> ctx.Parameters.TryGetValue(name, out var p) && p is T; Try / catch
try { return context.GetJobParameter<T>(name); }
catch (InvalidOperationException ex) { /* inspect ex.InnerException (InvalidCastException), fix the requested type */ } Prevention
- Document the runtime type of every parameter your filters write, and read with that exact type.
- Hangfire's built-in CurrentCulture/CurrentUICulture parameters are strings — always request GetJobParameter<string>.
- Use a shared constants/types file so writers and readers agree on parameter contracts.
When it happens
Trigger: Calling context.GetJobParameter<int>("CurrentCulture") when the stored value is a string; retrieving a parameter that CaptureCultureAttribute stored as a string name while expecting a CultureInfo; a custom filter writing a value of one type and another filter reading it as another.
Common situations: Mismatched types between a custom IClientFilter that writes a parameter and an IServerFilter that reads it; reading Hangfire's built-in CurrentCulture/CurrentUICulture parameters (stored as strings) with the wrong generic; version skew where a parameter's serialized representation changed.
Related errors
- context
- Could not set parameter for a created job.
- Expression body should be of type `MethodCallExpression`
- The type `{method.DeclaringType}` must be derived from the `
- Could not get a value of the job parameter `{name}`. See inn
AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13).
Data as JSON: /api/errors/fd216574620148f6.
Report an issue: GitHub.