{"record":{"id":"32887816f6149536","repo":"elsa-workflows/elsa-core","slug":"invalid-target-type-objectconverter","errorCode":null,"errorMessage":"Invalid target type.","messagePattern":"Invalid target type\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Expressions/Helpers/ObjectConverter.cs","lineNumber":374,"sourceCode":"                DateTimeOffset dateTimeOffset => dateTimeOffset.DateTime,\n                DateOnly date => new(date.Year, date.Month, date.Day),\n                _ => throw new ArgumentException(\"Invalid value type.\")\n            },\n            { } t when t == typeof(DateTimeOffset) => value switch\n            {\n                DateTime dateTime => new(dateTime),\n                DateTimeOffset dateTimeOffset => dateTimeOffset,\n                DateOnly date => new(date.Year, date.Month, date.Day, 0, 0, 0, TimeSpan.Zero),\n                _ => throw new ArgumentException(\"Invalid value type.\")\n            },\n            { } t when t == typeof(DateOnly) => value switch\n            {\n                DateTime dateTime => new(dateTime.Year, dateTime.Month, dateTime.Day),\n                DateTimeOffset dateTimeOffset => new(dateTimeOffset.Year, dateTimeOffset.Month, dateTimeOffset.Day),\n                DateOnly date => date,\n                _ => throw new ArgumentException(\"Invalid value type.\")\n            },\n            _ => throw new ArgumentException(\"Invalid target type.\")\n        };\n    }\n}\n","sourceCodeStart":356,"sourceCodeEnd":378,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Expressions/Helpers/ObjectConverter.cs#L356-L378","documentation":"ConvertAnyDateType throws ArgumentException \"Invalid target type.\" when the requested target type is not one of DateTime, DateTimeOffset, or DateOnly. The date-conversion helper only supports those three targets by design.","triggerScenarios":"Calling ConvertTo (reaching ConvertAnyDateType) with a date-like intent but an unsupported target type, e.g. TimeOnly, TimeSpan, or a custom date wrapper type.","commonSituations":"Attempting to convert to TimeOnly or custom calendar types expecting ObjectConverter to support them.","solutions":["Target only DateTime, DateTimeOffset, or DateOnly and post-process (e.g. convert DateTime to TimeOnly via new TimeOnly(dt.Hour, dt.Minute))","Parse TimeOnly strings directly with TimeOnly.Parse before/instead of ConvertTo","Add a custom type converter for the target type if it must be supported","Catch ArgumentException for unsupported target types and handle it as a configuration error"],"exampleFix":"// before\nvar t = (TimeOnly)ObjectConverter.ConvertTo(\"08:30\", typeof(TimeOnly));\n// after\nvar t = TimeOnly.Parse(\"08:30\", CultureInfo.InvariantCulture);","handlingStrategy":"validation","validationCode":"bool isSupportedDateTarget(Type t) => t == typeof(DateTime) || t == typeof(DateTimeOffset) || t == typeof(DateOnly);","typeGuard":null,"tryCatchPattern":"try { result = ObjectConverter.ConvertTo(v, targetType); }\ncatch (ArgumentException ex) when (ex.Message == \"Invalid target type.\") { throw new NotSupportedException($\"{targetType} is not a supported date target\"); }","preventionTips":["Only target DateTime, DateTimeOffset, or DateOnly via ConvertTo","Handle TimeOnly/TimeSpan conversions with dedicated parsing","Add custom converters for special date-like types"],"tags":["csharp","datetime","type-conversion","unsupported-target"],"backgroundTag":"unsupported-operation","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"}