{"record":{"id":"747a83bbea6830b2","repo":"dotnet/maui","slug":"cannot-convert-value-into-destinationtype","errorCode":null,"errorMessage":"Cannot convert \"{value}\" into {destinationType}","messagePattern":"Cannot convert \"(.+?)\" into (.+?)","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/DateTimeTypeConverter.cs","lineNumber":64,"sourceCode":"            return ConvertToDestinationType(dateOnly, destinationType, culture);\n        }\n        else if (value is DateTime dateTime)\n        {\n            return ConvertToDestinationType(dateTime, destinationType, culture);\n        }\n        else if (value is string stringValue)\n        {\n            if (DateTime.TryParse(stringValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))\n            {\n                return ConvertToDestinationType(dateTime, destinationType, culture);\n            }\n            else if (DateOnly.TryParse(stringValue, CultureInfo.InvariantCulture, out dateOnly))\n            {\n                return ConvertToDestinationType(dateOnly, destinationType, culture);\n            }\n        }\n\n        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}\");","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/DateTimeTypeConverter.cs#L46-L82","documentation":"DateTimeTypeConverter.ConvertTo throws NotImplementedException when ConvertToDestinationType cannot handle the request for a string-sourced value. It only succeeds when the string parses as DateTime/DateOnly AND the destinationType is one ConvertToDestinationType supports. If the string fails both TryParse calls, or parses but destinationType is unsupported, it throws.","triggerScenarios":"Calling ConvertTo with a string value that is not a parseable date, or a parseable date whose destinationType is neither string, DateTime, nor DateOnly (via the string branch).","commonSituations":"Serialization/designer code requesting conversion to an InstanceDescriptor or other Type; passing an unparseable date string through the ConvertTo path.","solutions":["Ensure the source string is invariant-culture ISO 8601 parseable.","Ensure destinationType is string, DateTime, or DateOnly.","Pass a DateTime/DateOnly instance instead of a string so the typed ConvertToDestinationType overload handles it."],"exampleFix":"// before\nconverter.ConvertTo(null, CultureInfo.InvariantCulture, \"tomorrow\", typeof(DateTime)); // unparseable -> throws\n\n// after\nconverter.ConvertTo(null, CultureInfo.InvariantCulture, DateTime.Today.AddDays(1), typeof(string));","handlingStrategy":"validation","validationCode":"static readonly HashSet<Type> _ok = new() { typeof(string), typeof(DateTime), typeof(DateOnly) };\nbool CanConvertTo(Type dest) => _ok.Contains(dest);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only request string/DateTime/DateOnly as ConvertTo destinations.","Pass typed DateTime/DateOnly instances instead of raw strings.","Wrap ConvertTo in try/catch NotImplementedException if the source is untrusted."],"tags":["typeconverter","datetime","convertto","parsing"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}