dotnet/maui · error · NotImplementedException

Cannot convert "{dateOnly}" into {destinationType}

Error message

Cannot convert "{dateOnly}" into {destinationType}

What it means

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

Source

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

        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}");
    }

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

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

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Request only string, DateTime, or DateOnly as the destination type.
  2. If you need another representation, convert manually after obtaining a DateTime via the supported path.

Example fix

// before
converter.ConvertTo(ctx, culture, DateOnly.FromDateTime(DateTime.Now), typeof(DateTimeOffset)); // unsupported target

// after
var dt = (DateTime)converter.ConvertTo(ctx, culture, DateOnly.FromDateTime(DateTime.Now), typeof(DateTime));
Defensive patterns

Strategy: type-guard

Validate before calling

static bool SupportedDateOnlyTarget(Type? t) =>
    t == typeof(string) || t == typeof(DateTime) || t == typeof(DateOnly);

Type guard

static bool IsSupportedDestination(Type? t) => t is not null && (t == typeof(string) || t == typeof(DateTime) || t == typeof(DateOnly));

Prevention

When it happens

Trigger: A designer/serializer or custom code requesting ConvertTo from a DateOnly value to an unsupported destinationType.

Common situations: XAML designer serialization paths; third-party serializers asking for non-supported destination types.

Related errors


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