Task<> does not contain a definition for 'GetAwaiter'

后端 未结 11 1255
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 07:11

Client

iGame Channel = new ChannelFactory ( new BasicHttpBinding ( BasicHttpSecurityMode . None ) , new EndpointAddress ( new Uri ( \"http://loc         


        
11条回答
  •  离开以前
    2020-11-30 07:57

    I had this problem because I was calling a method

    await myClass.myStaticMethod(myString);
    

    but I was setting myString with

    var myString = String.Format({some dynamic-type values})
    

    which resulted in a dynamic type, not a string, thus when I tried to await on myClass.myStaticMethod(myString), the compiler thought I meant to call myClass.myStaticMethod(dynamic myString). This compiled fine because, again, in a dynamic context, it's all good until it blows up at run-time, which is what happened because there is no implementation of the dynamic version of myStaticMethod, and this error message didn't help whatsoever, and the fact that Intellisense would take me to the correct definition didn't help either.
    Tricky!

    However, by forcing the result type to string, like:

    var myString = String.Format({some dynamic-type values})
    

    to

    string myString = String.Format({some dynamic-type values})
    

    my call to myStaticMethod routed properly

提交回复
热议问题