[英]Getting an Async error when I'm not using an Async function?
I have this function as part of a api to update data after a payment has been confirmed. 确认付款后,我将此功能作为api的一部分来更新数据。 It all works and updates the data but fails to redirect to the specified URl and throws this error: 所有这些都可以工作并更新数据,但是无法重定向到指定的UR1并引发以下错误:
I don't understand why I'm getting it as I'm not using async anywhere? 我不明白为什么要得到它,因为我在任何地方都不使用异步? Help would be appreciated. 帮助将不胜感激。
public HttpResponseMessage PaymentConfirmed(string id, string email, string status, string amount, string product)
{
if(status == "Paid")
{
var Id = id;
var Email = email;
var uid = Convert.ToInt32(Id);
var userbyId = RepositoryHelper.GetPersonFromId(uid);
if (userbyId.UserType == "Donation")
{
RepositoryHelper.UpdateDonation(userbyId, amount);
}
if (userbyId.UserType == "Sponsor")
{
var school = RepositoryHelper.GetSchoolByUser(userbyId);
RepositoryHelper.AddFreeUsers(school);
}
if (userbyId.UserType == "School" || userbyId.UserType == "Pupil")
{
var complete = RepositoryHelper.UpgradeToPaid(userbyId);
}
SendUserPaymentConfirmed(userbyId);
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Moved);
response.Headers.Location = new Uri("http://url here");
return response;
}
return null;
}
You can try by putting an await in front of these method calls like: 您可以尝试在这些方法调用之前放置一个等待,例如:
await RepositoryHelper.UpdateDonation
await RepositoryHelper.AddFreeUsers
await RepositoryHelper.UpgradeToPaid
await SendUserPaymentConfirmed
Then in method declaration change it : 然后在方法声明中更改它:
public Task<HttpResponseMessage> PaymentConfirmed
Build the project and fix where there are errors. 构建项目并修复存在错误的地方。 Most likely the methods that does not support async will complain or will have errors. 不支持异步的方法很可能会抱怨或出现错误。 Then run the API again and see if you still get the same error. 然后再次运行API,看看是否仍然出现相同的错误。
user error!!!!!! 用户错误!!!!
Found the issue, although my send message returned a void it had this nestled within it client.SendAsync(mailMessage, null);
发现了问题,尽管我的发送消息返回了一个无效值,但它client.SendAsync(mailMessage, null);
在其中client.SendAsync(mailMessage, null);
Removed it and all works fine 删除它,一切正常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.