我在使用下面的一组代码时遇到以下错误,它在“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 就不可能确切知道问题出在哪里,但看起来您正在 await
ing 某些不应该被 await
ed 的内容。
拆分 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/