elsa-workflows/elsa-core · error · ArgumentException
Invalid value type.
Error message
Invalid value type.
What it means
Thrown by the private ConvertAnyDateType helper in ObjectConverter when the supplied value is neither a DateTime nor a DateTimeOffset. It is a generic guard: any other runtime type passed through ConvertTo to a date target type fires this exception, so callers must ensure the source value is one of the two supported date kinds before conversion.
Solutions
- Pass DateTime or DateTimeOffset values to date-typed conversions
- Parse strings with DateTime.Parse/DateTimeOffset.Parse before calling ConvertTo
- Catch ArgumentException and handle the fallback
Example fix
// before
var d = ObjectConverter.ConvertTo<DateTime>("2024-01-01");
// after
var d = DateTime.Parse("2024-01-01", CultureInfo.InvariantCulture); Defensive patterns
Strategy: type-guard
Validate before calling
if (value is not (DateTime or DateTimeOffset))
value = DateTime.Parse(value.ToString()!, CultureInfo.InvariantCulture); Type guard
static bool IsDateValue(object? v) => v is DateTime or DateTimeOffset;
Try / catch
try { d = ObjectConverter.ConvertTo<DateTime>(v); } catch (ArgumentException) { d = DateTime.MinValue; } Prevention
- Pass strongly-typed DateTime/DateTimeOffset values
- Parse strings to dates before conversion
- Prefer DateTimeOffset for timezone-aware values
When it happens
Trigger: ConvertTo<DateTime> with a value like a string or long that survived earlier conversion steps and reached the date branch unconverted.
Common situations: Workflow inputs carrying date-as-string into a DateTime-typed property after ChangeType did not handle it; deserialized JsonElement values.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Invalid target type.
- A conversation ID is required. (Parameter 'conversation')
- A conversation user ID is required. (Parameter…
- Cannot deserialize to .
- Failed to deserialize
AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13).
Data as JSON: /api/errors/e218e44b04fd6b7c.
Report an issue: GitHub.
Appendix: source
Thrown at src/clients/Elsa.Api.Client/Extensions/ObjectConverter.cs:218
return dateTypes.Contains(type);
}
/// <summary>
/// Converts any date type to the specified target type.
/// </summary>
/// <param name="value">Any of <see cref="DateTime"/> or <see cref="DateTimeOffset"/>.</param>
/// <param name="targetType">Any of <see cref="DateTime"/> or <see cref="DateTimeOffset"/>.</param>
/// <returns>The converted value.</returns>
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is not of type <see cref="DateTime"/> or <see cref="DateTimeOffset"/>.</exception>
private static object ConvertAnyDateType(object value, Type targetType)
{
return targetType switch
{
{ } t when t == typeof(DateTime) => value switch
{
DateTime dateTime => dateTime,
DateTimeOffset dateTimeOffset => dateTimeOffset.DateTime,
_ => throw new ArgumentException("Invalid value type.")
},
{ } t when t == typeof(DateTimeOffset) => value switch
{
DateTime dateTime => new DateTimeOffset(dateTime),
DateTimeOffset dateTimeOffset => dateTimeOffset,
_ => throw new ArgumentException("Invalid value type.")
},
_ => throw new ArgumentException("Invalid target type.")
};
}
}View on GitHub (pinned to fe9217bdfa)