Generated Client in .NET Framework 4.8

Hi all

We are in the process of migrating a legacy application from .NET framework 4.8 to dotnet core.

In this scenario, we still need to generate a REST-API client via servicestack CLI in the old 4.8 project. We have models using the dotnet core DateOnly type to represent a date field without the time component.

If this type is defined on an api model this type is 1:1 generated in the .net 4.8 application. Unfortunately .net 4.8 does not support DateOnly. What would be a good way to get arround this issue?

If possible, we would like to keep the dotnet core api model definition clean with DateOnly

Have you tried using https://www.nuget.org/packages/Portable.System.DateTimeOnly?

Source code: https://github.com/OlegRa/System.DateTimeOnly

We have tried this. It works only in one direction. Request from dontet core to .net 4.8 are working good, the other way arround, we get parsing exceptions.
e.g.

Could not deserialize 'appliaction/json' requst using xxxx.PostSaveAdvertRequest'
Error: The JSON value could not be converted to System.DateOnly

Do we have to add the converter somewhere in the servicestack startup in .net 4.8?

I’m not aware of anyone trying to use .NET 6+ Types in .NET Framework, it’s going to be very fragile given it’s relying on 3rd Party packages to shim a built-in Data Type.

Since they’re unknown types requiring custom serialization you’re going to have to register custom deserialization for the foreign types, something like:

JsConfig<DateOnly>.DeSerializeFn = x => 
    DateOnly.FromDateTime(DateTimeSerializer.ParseShortestXsdDateTime(x));

JsConfig<TimeOnly>.DeSerializeFn = x =>  
    TimeOnly.FromTimeSpan(DateTimeSerializer.ParseTimeSpan(x));