gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 22:57:27 26 4
gpt4 key购买 nike

我在使用下面的一组代码时遇到以下错误,它在“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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com