_This issue has been moved from a ticket on Developer Community._
[severity:It's more difficult to complete my work]
I discovered this in a new Console app that I was writing. I created a stripped down version to the bare minimum and narrowed the problem down to the . ToListAsync() in a database access.
This works
public async void Start()
{
try
{
List<Order> Orders = (from o in _context. Tbl_Orders
where o.JobNumber == "DRG130"
select o). AsNoTracking(). ToList();
//Console.WriteLine($"Order Count: {Orders.Count}");
Console.WriteLine("Completed");
}
catch (Exception ex)
{
Console.WriteLine(ex. ToString());
throw;
}
Console.WriteLine("End");
}
This does not
public async void Start()
{
try
{
List<Order> Orders = await (from o in _context. Tbl_Orders
where o.JobNumber == "DRG130"
select o). AsNoTracking(). ToListAsync();
//Console.WriteLine($"Order Count: {Orders.Count}");
Console.WriteLine("Completed");
}
catch (Exception ex)
{
Console.WriteLine(ex. ToString());
throw;
}
Console.WriteLine("End");
}
Not only does it not work, but it also does not throw an exception, it simply crashes with nothing in the Output window, nothing on the console and it does not hit the breakpoint in the 'catch' clause.
Dot Net Core 3.1.402
EF Core 3.1.7 (3.1.8 behaves in a similar manner)
VS2019 16.7.3
Any help would be greatly appreciated.
Thanks.
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
(no solutions)
Use async Task not async void. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/async-return-types#void-return-type
the below code also crashes the same way.
public async Task
{
ResultDTO
try
{
var orders = await _dbContext.Order.Where(x => x.OrderStatusId == 1).ToListAsync();
}
catch(Exception ep)
{
}
return Result;
}
Dot Net Core 3.1.402
EF Core 3.1.7 (3.1.8 behaves in a similar manner)
VS2019 16.7.3
@chaitanyasingu can you please open a new issue with a runnable code sample that shows the crash?
I just Use this await Task.FromResult(query.ToList());
Most helpful comment
Use
async Tasknotasync void. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/async-return-types#void-return-type