我正在使用hellosign c#api,当我使用以下代码调用帐户信息功能时
var helloSign = new HelloSignClient("username", "password");
Account account = await helloSign.Account.GetAsync();
Console.WriteLine("Your current callback: " + account.CallbackUrl);
我收到以下错误。
Error 2 The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'.
下面是GetAsync方法
public async Task<Account> GetAsync()
{
AccountWrapper accountWrapper = await helloSignService.MakeRequestAsync<AccountWrapper>(settings.HelloSignSettings.Endpoints.Account.Get);
return accountWrapper.Account;
}
这是帐户类的类型
public class Account : AccountCondensedWithRole
{
[JsonProperty("callback_url")]
public string CallbackUrl { get; internal set; }
}
有人可以告诉我如何调用它或如何调试这个???
答案 0 :(得分:4)
信息很清楚。此行必须位于标有async
的方法中:
Account account = await helloSign.Account.GetAsync();
答案 1 :(得分:2)
你应该在这个
的异步方法中包装这个块public async Task<Type> MethodAsync(){
// other code if needed ....
var helloSign = new HelloSignClient("username", "password");
Account account = await helloSign.Account.GetAsync();
Console.WriteLine("Your current callback: " + account.CallbackUrl);
return type;
}
答案 2 :(得分:1)
您只能在异步方法中使用await。
以下是针对同一问题的另一个问题await operator