sendgrid-csharp: Async broken in library, causing deadlocks and responses not returning in non-console apps
Hi, I’m using the example code to send email on MVC web app but it not response on the line dynamic response = sg.client.mail.send.post(requestBody: mail.Get()); even it has been sent successfully. Am I missing something?
String apiKey = "APIKEY";
dynamic sg = new SendGrid.SendGridAPIClient(apiKey);
Email from = new Email("test@example.com");
String subject = "Hello World from the SendGrid CSharp Library";
Email to = new Email("test@example.com");
Content content = new Content("text/plain", "Textual content");
Mail mail = new Mail(from, subject, to, content);
dynamic response = sg.client.mail.send.post(requestBody: mail.Get());
Note: the example code work fine on console app only (response after post)
Thanks
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 1
- Comments: 66 (31 by maintainers)
Links to this issue
Commits related to this issue
- Merge pull request #235 from MikeRalphson/patch-1 Fix typos — committed to gabrielkrell/sendgrid-csharp by thinkingserious 10 years ago
This issue is fixed in version 7.0.2: https://github.com/sendgrid/sendgrid-csharp/releases/tag/v7.0.2
@alanhouck thanks for confirming!!!
I will push out an update and I’d like to swag out everyone on this thread. Please send your T-shirt size and mailing address to dx@sendgrid.com 😃
Please try:
return responseSendAsync(email).Wait();withpublic async Task SendAsync(Common.Emailing.Email email)withpublic static async Task<Response> SendAsync(Common.Emailing.Email email)Also, when you say "The only email that gets delivered is the one sent to “tawani@gmail.com”. Do you mean that when you try your code with that email it works fine, but when you try again with any other email it does not work? Could you try sending to dx@sendgrid.com?
Hello @tawani,
I have tried to reproduce, but I am not getting any errors, the button gets updated with the string “Accepted” and the email gets delivered with the following code:
Please take a look and let me know what you think.
An exception of type ‘Microsoft.CSharp.RuntimeBinder.RuntimeBinderException’ occurred in System.Web.Mvc.dll but was not handled in user code
Additional information: SendGrid.CSharp.HTTP.Client.Response enthält keine Definition für GetAwaiter.
@thinkingserious I was experimenting with the ConfigureAwait(false) earlier today and had no joy. Thankfully I checked this thread and tried adding it to the exact spots in the code you mentioned and it worked for me. Thanks!
@thinkingserious
SendEmail()is a Web API method; it’s triggered by an HTTP POST. So it’s called by the Web API routing framework.I had a sneaking suspicion that the solution would involve
ConfigureAwait(false). 😉I can reliably reproduce this in a Web API project. Here is my method:
I cannot use the client library at all until this is resolved. I’ll be making “raw” HTTP requests instead using
HttpClient.I am also facing same issue. Its working fine with console app. but when integrated with MVC application, its not returning response.