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

spawne with actorbuilder would cause AmbiguousMatchException #198

Open
ingted opened this issue Dec 15, 2020 · 3 comments
Open

spawne with actorbuilder would cause AmbiguousMatchException #198

ingted opened this issue Dec 15, 2020 · 3 comments

Comments

@ingted
Copy link

ingted commented Dec 15, 2020

Hi,

let deployRemotely address = Akka.Actor.Deploy(Akka.Actor.RemoteScope (Akka.Actor.Address.Parse address)) 
let spawnRemote systemOrContext remoteSystemAddress actorName expr otherOptionList =  
    Akka.FSharp.Spawn.spawne systemOrContext actorName expr ([Akka.FSharp.Spawn.SpawnOption.Deploy (deployRemotely remoteSystemAddress)] |> List.append otherOptionList)
let raddr = sprintf "akka.tcp://cluster-system@10.28.199.142:9000"
let actor9000 =
    spawnRemote system raddr ("remoteTest" + System.Guid.NewGuid().ToString())
        <@    
            fun (mailbox: Akka.FSharp.Actors.Actor<string>) ->
                let rec a () = Akka.FSharp.Actors.actor {
                    let! _msg = mailbox.Receive()
                    printfn "%s..." _msg
                    if false then
                        return ""
                    else
                        return! a()
                    
                }
                a()
        @> [Akka.FSharp.Spawn.SpawnOption.SupervisorStrategy(Akka.FSharp.Strategy.OneForOne(fun error ->
            match error with
            | _ -> Akka.Actor.Directive.Resume
            ))]

spawne with a remote deployment would cause AmbiguousMatchException:

System.Reflection.AmbiguousMatchException: More than one matching method found!
   at Hyperion.Extensions.TypeEx.GetMethodExt(MethodInfo& matchingMethod, Type type, String name, BindingFlags bindingFlags, Type[] parameterTypes)
   at Hyperion.Extensions.TypeEx.GetMethodExt(Type thisType, String name, BindingFlags bindingFlags, Type[] parameterTypes)

image

(Because Cont<> has two union cases)

Could anyone provide a hint about how to get a workaround?
Thank you!

@ingted
Copy link
Author

ingted commented Dec 15, 2020

My currently workaround:

                    if (i == parameterInfos.Length)
                    {

                        if (matchingMethod == null)
                            matchingMethod = methodInfo;
                        else
                        {
                            if (mbrs.Length == 2)
                            {
                                try
                                {
                                    var mbr0 = (MethodInfo)mbrs[0];
                                    var mbr1 = (MethodInfo)mbrs[1];
                                    var p0 = mbr0.GetParameters()[0].ParameterType;
                                    var p1 = mbr1.GetParameters()[0].ParameterType;
                                    var p0nm = p0.Name;
                                    var p1nm = p1.Name;
                                    var p0gt0 = p0.GenericTypeArguments[0].Name;
                                    var p0gt1 = p0.GenericTypeArguments[1].Name;
                                    if (p0nm == "FSharpFunc`2" && p1nm == "Cont`2" && p0gt0 == "Unit" && p0gt1 == "Cont`2") { }
                                    else
                                    {
                                        throw new AmbiguousMatchException(
                                            "More than one matching method found0!");
                                    }
                                }
                                catch
                                {
                                    throw new AmbiguousMatchException(
                                            "More than one matching method found1!");
                                }
                            }
                            else
                            {

                                throw new AmbiguousMatchException(
                                    "More than one matching method found!");
                            }
                        }
                    }

use if (p0nm == "FSharpFunc2" && p1nm == "Cont2" && p0gt0 == "Unit" && p0gt1 == "Cont`2") { }
to avoid exception

@ingted
Copy link
Author

ingted commented Dec 15, 2020

Hi @Horusiath, do you think this would cover all spawne quotation expression cases?

@ingted ingted changed the title spawne with actorbuider would cause AmbiguousMatchException spawne with actorbuilder would cause AmbiguousMatchException Dec 15, 2020
@ingted
Copy link
Author

ingted commented Dec 15, 2020

I found this will not work for complex quotation...
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant