kevin-montrose / Jil

Fast .NET JSON (De)Serializer, Built On Sigil
MIT License
2.15k stars 253 forks source link

Reflection on TimeSpan.FromSeconds needs to specify the parameter types #364

Open tarekgh opened 3 days ago

tarekgh commented 3 days ago

The TimeSpan type includes the method FromSeconds(double), and in .NET 9.0, a new overload FromSeconds(long) was introduced. The reflection logic for FromSeconds needs to be updated to specify the exact parameter types. Without this fix, the code will throw exceptions such as:

 System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
  ---> Jil.DeserializationException: The type initializer for 'Jil.Deserialize.InlineDeserializer`1' threw an exception.
  ---> System.TypeInitializationException: The type initializer for 'Jil.Deserialize.InlineDeserializer`1' threw an exception.
  ---> System.Reflection.AmbiguousMatchException: Ambiguous match found for 'System.TimeSpan System.TimeSpan FromSeconds(Int64)'.
    at System.RuntimeType.GetMethodImplCommon(String name, Int32 genericParameterCount, BindingFlags bindingAttr, Binder binder, CallingConventions callConv, Type[] types, ParameterModifier[] modifiers)
    at System.Type.GetMethod(String name, BindingFlags bindingAttr)
    at Jil.Deserialize.InlineDeserializer`1..cctor()
tarekgh commented 3 days ago

@kevin-montrose could you please give this issue a priority? some users are already broken when using Jil on .NET 9.0. Look this issue reported back in July too https://github.com/kevin-montrose/Jil/issues/363.

CC @Mutuduxf