Unable to check variables when debugging .NET Async / Await Functions

I have a .NET 4.5 proj that uses async/await functionality.

When I try to check the / quickwatch link to a variable after a wait statement, I get the following:

The name 'id' does not exist in the current context

Know how to fix this so that I can debug it?

Change - here is the code

  [Fact] public async Task works_as_expected() { var repo = Config.Ioc.GetInstance<IAsyncRepository<Customer>>(); var work = Config.Ioc.GetInstance<IUnitOfWork>(); Customer c= new Customer() { FirstName = "__Micah", LastName = "__Smith_test", DateCreated = DateTime.Now, DateModified = DateTime.Now, Email = " m@m.com ", Phone = "7245551212" }; var id=await repo.Insert(c); // i can't inspect the value of id Assert.True(id > 0); } 
+7
source share
1 answer

This variable does not yet exist, so there is no way to check its value. It doesn't matter (yet).

It will not be technically determined until you reach the line of code that defines it, and it does not matter until you initialize it. Although you can technically check the value of a variable before it is ever assigned in some cases, that value will never be available in code (outside of unsafe code), so there is no reason to look at it.

As for when the memory will be allocated for this location (that is, when you have the opportunity to view it in the debugger), which will be after you reach the first line after the last await before the variable is used.

-2
source

All Articles