I have the following in an ASP.NET Core application (Startup.cs, Configure method):
I just added the async keyword, because I needed the await one...
So now, I am getting the following:
Error CS8031 Async lambda expression converted to a '
Task' returning delegate cannot return a value. Did you intend to return '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 => { ... });
}
What should I return in that case? I tried to return 0;, but the error message doesn't change...
PS. The OnTicketRecieved signature
namespace Microsoft.AspNetCore.Authentication
{
public class RemoteAuthenticationEvents : IRemoteAuthenticationEvents
{
public Func<TicketReceivedContext, Task> OnTicketReceived { get; set; }

OnTicketReceivedexpecting?OnTicketReceivedwants a delegate that returns aTask, i.e., a task with no result. I'd guess when you addedasync, your lambda's implicit return type becameasync Task. That means you can't return a value, so treat your lambda as if it's returningvoid. Just remove your return statement entirely.