{"record":{"id":"e218e44b04fd6b7c","repo":"elsa-workflows/elsa-core","slug":"invalid-value-type","errorCode":null,"errorMessage":"Invalid value type.","messagePattern":"Invalid value type\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/clients/Elsa.Api.Client/Extensions/ObjectConverter.cs","lineNumber":218,"sourceCode":"        return dateTypes.Contains(type);\n    }\n\n    /// <summary>\n    /// Converts any date type to the specified target type.\n    /// </summary>\n    /// <param name=\"value\">Any of <see cref=\"DateTime\"/> or <see cref=\"DateTimeOffset\"/>.</param>\n    /// <param name=\"targetType\">Any of <see cref=\"DateTime\"/> or <see cref=\"DateTimeOffset\"/>.</param>\n    /// <returns>The converted value.</returns>\n    /// <exception cref=\"ArgumentException\">Thrown if <paramref name=\"value\"/> is not of type <see cref=\"DateTime\"/> or <see cref=\"DateTimeOffset\"/>.</exception>\n    private static object ConvertAnyDateType(object value, Type targetType)\n    {\n        return targetType switch\n        {\n            { } t when t == typeof(DateTime) => value switch\n            {\n                DateTime dateTime => dateTime,\n                DateTimeOffset dateTimeOffset => dateTimeOffset.DateTime,\n                _ => throw new ArgumentException(\"Invalid value type.\")\n            },\n            { } t when t == typeof(DateTimeOffset) => value switch\n            {\n                DateTime dateTime => new DateTimeOffset(dateTime),\n                DateTimeOffset dateTimeOffset => dateTimeOffset,\n                _ => throw new ArgumentException(\"Invalid value type.\")\n            },\n            _ => throw new ArgumentException(\"Invalid target type.\")\n        };\n    }\n}","sourceCodeStart":200,"sourceCodeEnd":229,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/clients/Elsa.Api.Client/Extensions/ObjectConverter.cs#L200-L229","documentation":"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.","triggerScenarios":"ConvertTo<DateTime> with a value like a string or long that survived earlier conversion steps and reached the date branch unconverted.","commonSituations":"Workflow inputs carrying date-as-string into a DateTime-typed property after ChangeType did not handle it; deserialized JsonElement values.","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"],"exampleFix":"// before\nvar d = ObjectConverter.ConvertTo<DateTime>(\"2024-01-01\");\n// after\nvar d = DateTime.Parse(\"2024-01-01\", CultureInfo.InvariantCulture);","handlingStrategy":"type-guard","validationCode":"if (value is not (DateTime or DateTimeOffset))\n    value = DateTime.Parse(value.ToString()!, CultureInfo.InvariantCulture);","typeGuard":"static bool IsDateValue(object? v) => v is DateTime or DateTimeOffset;","tryCatchPattern":"try { d = ObjectConverter.ConvertTo<DateTime>(v); } catch (ArgumentException) { d = DateTime.MinValue; }","preventionTips":["Pass strongly-typed DateTime/DateTimeOffset values","Parse strings to dates before conversion","Prefer DateTimeOffset for timezone-aware values"],"tags":["dotnet","datetime","argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}