Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialize string to DateOnly fails on net6 #304

Closed
runerys opened this issue Mar 11, 2024 · 1 comment · Fixed by #305
Closed

Deserialize string to DateOnly fails on net6 #304

runerys opened this issue Mar 11, 2024 · 1 comment · Fixed by #305
Labels
bug Something isn't working

Comments

@runerys
Copy link
Contributor

runerys commented Mar 11, 2024

It seems to be a slight bug when deserializing a string to DateOnly on net6.

Reproduce

It looks like the test suite only runs on net8, not net6. Run it with target framework net6 to reproduce.

Locally it just failed when debugging the exact test. When running through the Test Explorer, it seems like the flag NET6_0_OR_GREATER was not set.

Fix

The code use reflection to find the Parse-method, but the current code only works for net8. The overload with only string and IFormatProvider was introduced in net8. Parse on net6 has 3 parameters.

// Include DateTimeStyle to work with both net 6 and net 8:
var parseDateOnly = typeof(DateOnly)
    .GetMethod(nameof(DateOnly.Parse), new[] { value.Type, typeof(IFormatProvider), typeof(DateTimeStyles) }); // <-- Last parameter

value = Expression.ConvertChecked(
    Expression.Call(
        null,
        parseDateOnly,
        value,
        Expression.Constant(CultureInfo.InvariantCulture),
        Expression.Constant(DateTimeStyles.RoundtripKind)), //<-- with DateTimeStyle
    target);

The same goes for TimeOnly just below in the same file.

I'm sorry for not providing a PR with a fix right away - might be back for it soon :)

If net6 is out-of-support for this library, then please close this issue :)

@dstelljes
Copy link
Member

Thanks for the report! We'll roll out 10.2.3 shortly with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants