0

I have following code in a class library to create a mailjet (https://github.com/mailjet/mailjet-apiv3-dotnet) contact list.

public async Task<ResultMessage> CreateContactList(string contactListName)
    {
        MailjetResponse response = null;
        ResultMessage resultMessage = null;
        try
        {
            var client = new MailjetClient(MjApikeyPublic, MjApikeyPrivate);
            MailjetRequest request = new MailjetRequest
            {
                Resource = Contactslist.Resource,
            }
                .Property(Contactslist.Name, contactListName);

            response = await client.PostAsync(request);
            resultMessage = GetResultMessage(response, exception: null);
        }
        catch (Exception e)
        {
            resultMessage = GetResultMessage(response: response, exception: e);
        }

        return resultMessage;
    }

This works fine when I use it with a console application, and when debugged it hits the below line and gets http response from mailjet. And when I check it in the mailjet profile I can see the contact list with passed name is created at their end.

resultMessage = GetResultMessage(response, exception: null);

But when I used the same with a ASP.NET MVC application, it does not receive the http response, the application hangs forever. And when debugged it never reaches the above line. But, the list gets created in the mailjet end, so the only issue is it does not capture the http response from the mailjet.

Can someone please help me?

BUDDHIKA
  • 306
  • 2
  • 8
  • 23
  • 1
    May i ask how CreateContactList is called? If it's called with .Wait() or .Result your problem could be a deadlock since your ASP.Net context gets blocked (see article by [Stephen Cleary](https://blog.stephencleary.com/2012/07/dont-block-on-async-code.html)). – Michael Hufnagel Jul 13 '18 at 12:28
  • What's `GetResultMessage` doing? From what you're saying, looks like an exception is being thrown. – Paulo Morgado Jul 14 '18 at 19:37

0 Answers0