This does not work:
public Task<T> FindFirstOrDefaultAsync(Expression<Func<T, bool>> predicate)
{
return _collection.Find(predicate).FirstOrDefaultAsync();
}
This works:
public T FindFirstOrDefault(Expression<Func<T, bool>> predicate)
{
return _collection.Find(predicate).FirstOrDefaultAsync().Result;
}
That method is invoked by:
public async Task<ExtendedProductDTO> GetProductByUniqueIDAsync(string id)
{
var product = await _productRepo.**FindFirstOrDefaultAsync**(i => i.UniqueID == id).ConfigureAwait(true);
return new ExtendedProductDTO(product != null, product);
}
And GetProductByUniqueIDAsync is invoked as:
try
{
var product3 = await _productService.GetProductByUniqueIDAsync("9988ad0a66f28fe8611962a06a593865c1c8103f87258e3920986fc2a4ba2d0e");
var product4 = await _productService.GetProductByUniqueIDAsync("6641020d80e10877a13a973592d934165de39c743f7a2fa3f78a8671ac2e9c5b");
}
catch (Exception ex)
{
Logger.Fatal(ex.Message, ex);
}
As said, I can reach the } of GetProductByUniqueIDAsync and all data is there (product and then ExtendedProductDTO).
When the exception is triggered (=always), the execution of the caller method is interrupted: no lines after " var product3 = ..." is reached.