fjoppe / Legivel

F# Yaml 1.2 parser
https://fjoppe.github.io/Legivel
The Unlicense
60 stars 5 forks source link

Caught AmbigousMatch in System.RuntimeType.GetMethodImpl #38

Open pkese opened 2 years ago

pkese commented 2 years ago

I have found an issue with Legivel and I'm providing reproduction code below.

#!/usr/bin/env -S dotnet fsi

#r "nuget: Open.Collections, 3.1.2"
//#r "nuget: Open.Collections, 2.11.3"
#r "nuget: Legivel, 0.4.6"

open Open.Collections
open Legivel.Serialization

type Document = {
    ages: OrderedDictionary<string,int>
}

"""
ages:
    john: 30
    mary: 25
    paul: 51
"""
|> Deserialize<Document>
|> Seq.iter (function
    | Success successInfo ->
        for kv in successInfo.Data.ages do
            printfn $"{kv.Key} -> {kv.Value}"
    | Error error ->
        printfn "Error: %A" error)

After updating an external library that I'm using for OrderedDictionary, the code suddenly started throwing an exception:

System.Reflection.AmbiguousMatchException: Ambiguous match found.
   at System.RuntimeType.GetMethodImplCommon(String name, Int32 genericParameterCount, BindingFlags bindingAttr, Binder binder, CallingConventions callConv, Type[] types, ParameterModifier[] modifiers)
   at System.RuntimeType.GetMethodImpl(String name, BindingFlags bindingAttr, Binder binder, CallingConventions callConv, Type[] types, ParameterModifier[] modifiers)
   at System.Type.GetMethod(String name, BindingFlags bindingAttr)
   at System.Type.GetMethod(String name)
   at Legivel.Customization.Mapping.Legivel-Mapper-Model-IYamlToNativeMapping-map@456-17.Invoke(Tuple`2 tupledArg)
   at Microsoft.FSharp.Collections.ListModule.Iterate[T](FSharpFunc`2 action, FSharpList`1 list) in /build/dotnet6-vdouV1/dotnet6-6.0.110/src/fsharp/artifacts/source-build/self/src/src/fsharp/FSharp.Core/list.fs:line 102
   at Legivel.Customization.Mapping.Legivel-Mapper-Model-IYamlToNativeMapping-map@444-14.Invoke(FSharpList`1 possibleData)
   at Legivel.Customization.Mapping.mapKeyValue@212-1.Invoke(RecordFieldMapping fm)
   at Legivel.Customization.Mapping.mapKeyValue@209(RecordMappingInfo this, ProcessMessages msgList, AllTryFindIdiomaticMappers mappers, ProcessMessages pm, Node org, String kn, Node v)
   at Legivel.Customization.Mapping.Legivel-Mapper-Model-IYamlToNativeMapping-map@229-7.Invoke(NodeData`1 kf)
   at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x) in /build/dotnet6-vdouV1/dotnet6-6.0.110/src/fsharp/artifacts/source-build/self/src/src/fsharp/FSharp.Core/local.fs:line 244
...

My workaround for was to pin the Open.Collections library to an older version, however I'm sharing this reproduction here, because I assume it might be a bug in Legivel: OrderedDictionary<'K,'V> properly implements System.Collections.Generic.IDictionary<'K,'V> interface, so there's no reason Legivel wouldn't recognize it as such and call dictionary methods on its instances.

fjoppe commented 1 year ago

Hi pkese,

I have started looking into this. But it first pulls me into upgrade issues...