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

后端 未结 11 1257
佛祖请我去吃肉
佛祖请我去吃肉 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:50

    In my case just add using System; solve the issue.

    0 讨论(0)
  • 2020-11-30 07:55

    I had this issue in one of my projects, where I found that I had set my project's .Net Framework version to 4.0 and async tasks are only supported in .Net Framework 4.5 onwards.

    I simply changed my project settings to use .Net Framework 4.5 or above and it worked.

    0 讨论(0)
  • 2020-11-30 07:56

    You have to install Microsoft.Bcl.Async NuGet package to be able to use async/await constructs in pre-.NET 4.5 versions (such as Silverlight 4.0+)

    Just for clarity - this package used to be called Microsoft.CompilerServices.AsyncTargetingPack and some old tutorials still refer to it.

    Take a look here for info from Immo Landwerth.

    0 讨论(0)
  • 2020-11-30 07:57

    Make sure your .NET version 4.5 or greater

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题