0

I was confronted with unexpected and strange behavior when working with async/await methods. Execution is breaking after calling await. There is no exceptions or async continue, just break and nothing. Here is code:

public async Task<IEnumerable<MailChimpUser>> GetAllMembersAsync(string listName) { try { //Breaks here var list = await GetListByName(listName); //Nevertheless, if extract method code //var lists = await _apiManager.Lists.GetAllAsync().ConfigureAwait(false); //list = lists.FirstOrDefault(l => l.Name == name); //the execution will continueя var members = await _apiManager.Members.GetAllAsync(list.Id).ConfigureAwait(false); var result = members.Select(m => new MailChimpUser() { ... } ); //the same behavior here, after the return it does not return to the method that awaiting it. return result; } catch (Exception ex) { var logger = LogManager.GetCurrentClassLogger(); logger.Error(ex, ex.Message, new object[] { }); throw ex; } } private async Task<MailChimp.Net.Models.List> GetListByName(string name) { try { var lists = await _apiManager.Lists.GetAllAsync().ConfigureAwait(false); var list = lists.FirstOrDefault(l => l.Name == name); if (list == null) throw new Exception(String.Format("MailChimp: List \"{0}\" not found", name)); return list; } catch (Exception ex) { var logger = LogManager.GetCurrentClassLogger(); logger.Error(ex, ex.Message, new object[] { }); throw ex; } } 

Can you tell me what I'm doing wrong and how can I fix it?

13
  • 2
    throw ex; should be throw;. Commented Sep 20, 2017 at 9:36
  • @UweKeim not if they explicitly wants to reset the stack trace Commented Sep 20, 2017 at 9:38
  • 2
    What do you mean exactly by "break"? I can't see where you call GetAllMembersAsync, only GetAllAsync. Commented Sep 20, 2017 at 9:38
  • 2
    Please show how you call the methods. If you don't await those methods or try to access the Result of the returned Tasks, you may miss an exceptions thrown by GetListByName. Commented Sep 20, 2017 at 9:56
  • 2
    We still can't see the whole callstack. But do read Using ConfigureAwait(false) to avoid deadlocks is a dangerous practice Commented Sep 20, 2017 at 11:15

1 Answer 1

1

The problem was that I forgot ConfigureAwait(false)

var list = await GetListByName(listName).ConfigureAwait(false); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.