0

Async method (works fine in async code):

public async Task<ServiceResult<Config>> GetConfigAsync(string id)
        {
            var entity = await _entityRepo.FindAsync(t => t.Id == id);
            if (entity == null) throw new Exception($"entity Id {id} is invalid");
            var result = JsonConvert.DeserializeObject<Config>(entity.Config);
            return new ServiceResult<Config>(result);
        }

And I try to call it from sync code:

var configTask = _configurationService.GetConfigAsync(id);
var config = configTask.GetAwaiter().GetResult();

I can't see any issue, so it I just stuck.

What I do wrong?

9
  • 1
    What makes you think it is not working? Commented Aug 30, 2017 at 20:11
  • compiler error? runtime exception? Commented Aug 30, 2017 at 20:11
  • 1
    Is the sync code being called from async code? If so you have a context deadlock. To test add ConfigureAwait: var entity = await _entityRepo.FindAsync(t => t.Id == id).ConfigureAwait(false); Commented Aug 30, 2017 at 20:12
  • 2
    Don't Block on Async Code Commented Aug 30, 2017 at 20:15
  • 1
    @JoelFan If I debug it. It works. Commented Aug 30, 2017 at 20:18

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.