c# - 不包含 'GetAwaiter' 的定义

标签 c# async-await api-eveonline

我在使用下面的一组代码时遇到以下错误,它在“alliancelookup”行上出错,我不确定我做错了什么,但我自己看不到任何东西。我运行到 crest 的查询似乎运行良好,但我遇到的问题似乎与 Awaiter 有关,我想知道是否有办法解决这个问题?

DynamicCrest crest = new DynamicCrest();
var root = await crest.GetAsync(crest.Host);
var alliancelookup = await (await root.GetAsync(r => r.alliances)).First(i => i.shortName == e.GetArg("allianceticker").ToUpper());
allianceid = alliancelookup.id;

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Dynamic.ExpandoObject' does not contain a definition for 'GetAwaiter' at CallSite.Target(Closure , CallSite , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at ***.Program.<>c.<b__2_10>d.MoveNext() in C:\Users---\Documents\Visual Studio 2015\Projects------\Program.cs:line 95

最佳答案

如果没有 minimal, complete, verifiable example 就不可能确切知道问题出在哪里,但看起来您正在 awaiting 某些不应该被 awaited 的内容。

拆分 alliancelookup 行:

// Asynchronously retrieve the alliances.
var alliances = await root.GetAsync(r => r.alliances);

// Synchronously get the first matching one.
var allianceLookup = alliances.First(i => i.shortName == e.GetArg("allianceticker").ToUpper());

可能有更好的方法,将过滤器移到异步代码中,但这取决于 DynamicCrest

关于c# - 不包含 'GetAwaiter' 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38570858/

相关文章:

c# - 使用 ObjectResult 将 EF6 转换为 EF 核心

c# - 有没有办法在 'publicly readable buckets' 上使用 Amazon .NET AWS SDK 的 AmazonS3 客户端而不指定 AWS 凭证?

c# - Entity Framework SaveChangesAsync 阻塞了我的 UI?

c# - IO绑定(bind)异步任务不异步执行

asynchronous - Dart :io clean up Futures that timeout? 是如何实现的

php - 循环遍历 XML,仅在特定 ID 处循环 "look"

c# - 如何在 ListView 的组标题中保存 IsExpanded 状态

c# - 为什么我的 ObservableCollection<MenuItem> 不会在 RaisePropertyChanged 上更新?

python - 夏娃在线通过URL查询进行身份验证