转换为'Task'的异步lambda表达式返回委托不能返回值

Ser*_*rge 3 c# async-await asp.net-core

我在ASP.NET核心应用程序(Startup.cs,Configure方法)中有以下内容:

我刚刚添加了async关键字,因为我需要await一个...所以现在,我得到以下内容:

错误CS8031转换为' Task'返回委托的异步lambda表达式无法返回值.你有意回来' Task<T>'吗?

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, ITableRepositories repository)
{
    // ...  
    app.UseStaticFiles();    
    app.UseCookieAuthentication();

    app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
    {
        ClientId = Configuration["..."],
        Authority = Configuration["..."],
        CallbackPath = Configuration["..."],
        Events = new OpenIdConnectEvents
        {
            OnAuthenticationFailed = context => { return Task.FromResult(0); },
            OnRemoteSignOut = context => { return Task.FromResult(0); },
            OnTicketReceived = async context =>
            {
                var user = (ClaimsIdentity)context.Ticket.Principal.Identity;
                if (user.IsAuthenticated)
                {
                    var firstName = user.FindFirst(ClaimTypes.GivenName).Value;
                    // ...
                    List<Connection> myList = new List<Connection>() { c };
                    var results = await repository.InsertOrMergeAsync(myList);
                    var myConnection = (results.First().Result as Connection);                         
                }
                return Task.FromResult(0); // <<< ERROR HERE ....... !!!
            },
            OnTokenValidated = context => { return Task.FromResult(0); },
            OnUserInformationReceived = context => { return Task.FromResult(0); },
        }
    });

    app.UseMvc(routes =>        { ...        });
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

在那种情况下我该返回什么?我试过return 0;,但错误信息没有改变......

PS.该OnTicketRecieved签名

namespace Microsoft.AspNetCore.Authentication
{
    public class RemoteAuthenticationEvents : IRemoteAuthenticationEvents
    {
        public Func<TicketReceivedContext, Task> OnTicketReceived { get; set; }
Run Code Online (Sandbox Code Playgroud)

pok*_*oke 7

错误消息实际上是不言自明的:

转换为'Task'返回委托的异步lambda表达式无法返回值.你打算回来'Task<T>'吗?

所以你有一个async lambda表达式,它应该返回Task-not a Task<T>for any T.

但是当你这样做时,你return 0返回一个int,所以async方法的返回类型Task<int>不是Task.编译器要你做的是根本不返回任何值.

OnTicketReceived = async context =>
{
    await Task.Delay(100);
    return;
}
Run Code Online (Sandbox Code Playgroud)