{"record":{"id":"8b2315fbb204f866","repo":"dotnet/maui","slug":"cannot-convert-dateonly-into-destinationtype","errorCode":null,"errorMessage":"Cannot convert \"{dateOnly}\" into {destinationType}","messagePattern":"Cannot convert \"(.+?)\" into (.+?)","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/DateTimeTypeConverter.cs","lineNumber":82,"sourceCode":"        throw new NotImplementedException($\"Cannot convert \\\"{value}\\\" into {destinationType}\");\n    }\n\n    static object ConvertToDestinationType(DateOnly dateOnly, Type? destinationType, CultureInfo? culture)\n    {\n        if (destinationType == typeof(string))\n        {\n            return dateOnly.ToString( CultureInfo.InvariantCulture);\n        }\n        else if (destinationType == typeof(DateTime))\n        {\n            return dateOnly.ToDateTime(TimeOnly.MinValue);\n        }\n        else if (destinationType == typeof(DateOnly))\n        {\n            return dateOnly;\n        }\n\n        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}\");","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/DateTimeTypeConverter.cs#L64-L100","documentation":"ConvertToDestinationType(DateOnly,...) throws NotImplementedException when the destinationType is not string, DateTime, or DateOnly. The method handles exactly those three targets and rejects anything else (e.g. InstanceDescriptor, object, DateTimeOffset).","triggerScenarios":"A designer/serializer or custom code requesting ConvertTo from a DateOnly value to an unsupported destinationType.","commonSituations":"XAML designer serialization paths; third-party serializers asking for non-supported destination types.","solutions":["Request only string, DateTime, or DateOnly as the destination type.","If you need another representation, convert manually after obtaining a DateTime via the supported path."],"exampleFix":"// before\nconverter.ConvertTo(ctx, culture, DateOnly.FromDateTime(DateTime.Now), typeof(DateTimeOffset)); // unsupported target\n\n// after\nvar dt = (DateTime)converter.ConvertTo(ctx, culture, DateOnly.FromDateTime(DateTime.Now), typeof(DateTime));","handlingStrategy":"type-guard","validationCode":"static bool SupportedDateOnlyTarget(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.","For other formats, convert to DateTime then transform manually."],"tags":["typeconverter","dateonly","convertto","destinationtype"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}