{"record":{"id":"c9ed375a2e6747ca","repo":"dotnet/maui","slug":"cannot-convert-value-into-typeof-datetime","errorCode":null,"errorMessage":"Cannot convert \"{value}\" into {typeof(DateTime)}","messagePattern":"Cannot convert \"(.+?)\" into (.+?)","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/DateTimeTypeConverter.cs","lineNumber":39,"sourceCode":"            return dateTime;\n        }\n        if (value is DateOnly dateOnly)\n        {\n            return dateOnly.ToDateTime(TimeOnly.MinValue);\n        }\n        if (value is string stringValue)\n        {\n            if (DateOnly.TryParse(stringValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateOnly dateTimeOnly))\n            {\n                return dateTimeOnly.ToDateTime(TimeOnly.MinValue);\n            }\n            else if (DateTime.TryParse(stringValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))\n            {\n                return dateTime;\n            }\n        }\n\n        throw new NotImplementedException($\"Cannot convert \\\"{value}\\\" into {typeof(DateTime)}\");\n    }\n\n    public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type? destinationType)\n    {\n        if (value is DateOnly dateOnly)\n        {\n            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            }","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/DateTimeTypeConverter.cs#L21-L57","documentation":"DateTimeTypeConverter.ConvertFrom throws NotImplementedException when the incoming value cannot be parsed as a DateOnly or DateTime using the invariant culture. It first tries DateOnly.TryParse, then DateTime.TryParse; only if both fail (or the value is not a string) does it throw. Despite 'NotImplementedException', this is really an invalid-input conversion failure for the DateTime target type.","triggerScenarios":"XAML or SetValue passing a string that is not a parseable date (e.g. 'next tuesday', locale-specific formats with commas, empty string, non-string objects) to a DateTime-typed property; binding a string source to a DateTime target without a converter.","commonSituations":"Culture-specific date strings that the invariant culture rejects; malformed XAML date attributes; feeding a DateOnly/DateTime property from user input or a JSON string that is not ISO-formatted.","solutions":["Provide the date in an invariant-culture-parseable format: ISO 8601 'yyyy-MM-dd' or 'yyyy-MM-ddTHH:mm:ss'.","Pre-parse/validate the string in your code and pass a DateTime/DateOnly object instead of a string.","Register a custom TypeConverter or value converter if you must accept locale-specific formats."],"exampleFix":"// before\n<MyControl MyDate=\"13/08/2026\" /> <!-- depends on locale, often fails invariant parse -->\n\n// after\n<MyControl MyDate=\"2026-08-13\" /> <!-- ISO 8601, invariant-safe -->","handlingStrategy":"validation","validationCode":"// Validate before relying on the converter / assigning a string.\nbool IsParsableDate(string s) =>\n    DateOnly.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.None, out _) ||\n    DateTime.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.None, out _);","typeGuard":null,"tryCatchPattern":"try { dt = (DateTime)converter.ConvertFrom(null, CultureInfo.InvariantCulture, input); }\ncatch (NotImplementedException) { /* log, fallback to default date */ dt = default; }","preventionTips":["Always format date strings as ISO 8601 (yyyy-MM-dd or yyyy-MM-ddTHH:mm:ss).","Pre-parse user/JSON input and pass DateTime/DateOnly objects, not strings.","Avoid locale-specific date strings at property boundaries."],"tags":["typeconverter","datetime","dateonly","xaml","parsing"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}