{"record":{"id":"5996effac43c2174","repo":"dotnet/maui","slug":"cannot-convert-datetime-into-destinationtype","errorCode":null,"errorMessage":"Cannot convert \"{dateTime}\" into {destinationType}","messagePattern":"Cannot convert \"(.+?)\" into (.+?)","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/DateTimeTypeConverter.cs","lineNumber":100,"sourceCode":"        throw new NotImplementedException($\"Cannot convert \\\"{dateOnly}\\\" into {destinationType}\");\n    }\n\n    static object ConvertToDestinationType(DateTime dateTime, Type? destinationType, CultureInfo? culture)\n    {\n        if (destinationType == typeof(string))\n        {\n            return dateTime.ToString(CultureInfo.InvariantCulture);\n        }\n        else if (destinationType == typeof(DateTime))\n        {\n            return dateTime;\n        }\n        else if (destinationType == typeof(DateOnly))\n        {\n            return DateOnly.FromDateTime(dateTime);\n        }\n\n        throw new NotImplementedException($\"Cannot convert \\\"{dateTime}\\\" into {destinationType}\");\n    }\n}\n\n#endif","sourceCodeStart":82,"sourceCodeEnd":104,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/DateTimeTypeConverter.cs#L82-L104","documentation":"ConvertToDestinationType(DateTime,...) throws NotImplementedException when destinationType is not string, DateTime, or DateOnly. Mirrors the DateOnly overload: only those three targets are accepted.","triggerScenarios":"ConvertTo from a DateTime value to an unsupported destinationType such as InstanceDescriptor, DateTimeOffset, long (ticks), or a custom type.","commonSituations":"Designer/serialization requesting InstanceDescriptor; converting DateTime to a storage format the converter does not know.","solutions":["Limit destinationType to string, DateTime, or DateOnly.","Convert to DateTime first, then transform to the final type yourself."],"exampleFix":"// before\nconverter.ConvertTo(ctx, culture, DateTime.Now, typeof(long)); // ticks not supported\n\n// after\nvar s = (string)converter.ConvertTo(ctx, culture, DateTime.Now, typeof(string));\nvar ticks = DateTime.Parse(s, CultureInfo.InvariantCulture).Ticks;","handlingStrategy":"type-guard","validationCode":"static bool SupportedDateTimeTarget(Type? t) =>\n    t == typeof(string) || t == typeof(DateTime) || t == typeof(DateOnly);","typeGuard":"static bool IsSupportedDestination(Type? t) => t is not null && (t == typeof(string) || t == typeof(DateTime) || t == typeof(DateOnly));","tryCatchPattern":null,"preventionTips":["Restrict ConvertTo destinationType to string/DateTime/DateOnly.","Convert to DateTime first, then to your custom target manually."],"tags":["typeconverter","datetime","convertto","destinationtype"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}