dotnet/maui · error · NotImplementedException

Cannot convert "{value}" into {typeof(DateTime)}

Error message

Cannot convert "{value}" into {typeof(DateTime)}

What it means

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.

Source

Thrown at src/Controls/src/Core/DateTimeTypeConverter.cs:39

            return dateTime;
        }
        if (value is DateOnly dateOnly)
        {
            return dateOnly.ToDateTime(TimeOnly.MinValue);
        }
        if (value is string stringValue)
        {
            if (DateOnly.TryParse(stringValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateOnly dateTimeOnly))
            {
                return dateTimeOnly.ToDateTime(TimeOnly.MinValue);
            }
            else if (DateTime.TryParse(stringValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
            {
                return dateTime;
            }
        }

        throw new NotImplementedException($"Cannot convert \"{value}\" into {typeof(DateTime)}");
    }

    public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type? destinationType)
    {
        if (value is DateOnly dateOnly)
        {
            return ConvertToDestinationType(dateOnly, destinationType, culture);
        }
        else if (value is DateTime dateTime)
        {
            return ConvertToDestinationType(dateTime, destinationType, culture);
        }
        else if (value is string stringValue)
        {
            if (DateTime.TryParse(stringValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
            {
                return ConvertToDestinationType(dateTime, destinationType, culture);
            }

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Provide the date in an invariant-culture-parseable format: ISO 8601 'yyyy-MM-dd' or 'yyyy-MM-ddTHH:mm:ss'.
  2. Pre-parse/validate the string in your code and pass a DateTime/DateOnly object instead of a string.
  3. Register a custom TypeConverter or value converter if you must accept locale-specific formats.

Example fix

// before
<MyControl MyDate="13/08/2026" /> <!-- depends on locale, often fails invariant parse -->

// after
<MyControl MyDate="2026-08-13" /> <!-- ISO 8601, invariant-safe -->
Defensive patterns

Strategy: validation

Validate before calling

// Validate before relying on the converter / assigning a string.
bool IsParsableDate(string s) =>
    DateOnly.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.None, out _) ||
    DateTime.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.None, out _);

Try / catch

try { dt = (DateTime)converter.ConvertFrom(null, CultureInfo.InvariantCulture, input); }
catch (NotImplementedException) { /* log, fallback to default date */ dt = default; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/c9ed375a2e6747ca. Report an issue: GitHub.