dotnet/maui · error · NotImplementedException

Cannot convert "{value}" into {destinationType}

Error message

Cannot convert "{value}" into {destinationType}

What it means

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.

Source

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

            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);
            }
            else if (DateOnly.TryParse(stringValue, CultureInfo.InvariantCulture, out dateOnly))
            {
                return ConvertToDestinationType(dateOnly, destinationType, culture);
            }
        }

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

    static object ConvertToDestinationType(DateOnly dateOnly, Type? destinationType, CultureInfo? culture)
    {
        if (destinationType == typeof(string))
        {
            return dateOnly.ToString( CultureInfo.InvariantCulture);
        }
        else if (destinationType == typeof(DateTime))
        {
            return dateOnly.ToDateTime(TimeOnly.MinValue);
        }
        else if (destinationType == typeof(DateOnly))
        {
            return dateOnly;
        }

        throw new NotImplementedException($"Cannot convert \"{dateOnly}\" into {destinationType}");

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Ensure the source string is invariant-culture ISO 8601 parseable.
  2. Ensure destinationType is string, DateTime, or DateOnly.
  3. Pass a DateTime/DateOnly instance instead of a string so the typed ConvertToDestinationType overload handles it.

Example fix

// before
converter.ConvertTo(null, CultureInfo.InvariantCulture, "tomorrow", typeof(DateTime)); // unparseable -> throws

// after
converter.ConvertTo(null, CultureInfo.InvariantCulture, DateTime.Today.AddDays(1), typeof(string));
Defensive patterns

Strategy: validation

Validate before calling

static readonly HashSet<Type> _ok = new() { typeof(string), typeof(DateTime), typeof(DateOnly) };
bool CanConvertTo(Type dest) => _ok.Contains(dest);

Prevention

When it happens

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

Common situations: Serialization/designer code requesting conversion to an InstanceDescriptor or other Type; passing an unparseable date string through the ConvertTo path.

Related errors


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