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 :)
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.https://github.com/ch-robinson/dotnet-avro/blob/e1d712947c13c132f0da46df307d2e465fd6e3e3/src/Chr.Avro/Serialization/StringDeserializerBuilderCase.cs#L54
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 :)