Visual Studio 2015 Asynchronous Variables Not Displayed in Debugger

I have a .NET Core ASP.NET MVC 6 application, and I'm sure this is a bug in Visual Studio. If I place a breakpoint after the wait statement, the object does not appear in the locales, and I cannot hover over the check. But if I use a variable, it still works fine, and it is definitely full.

Something simple:

public async Task<IActionResult> Index()
    {
        var location = await _listingLocationService.GetLocationByAddress("123 Fake Street");
        return Content(location.Latitude.ToString() + " " +location.Longitude.ToString());
    }

If I put a breakpoint in the return statement, I cannot check the location. He does not appear anywhere. I can even remove the wait and put the .Result result at the end, and still nothing is displayed. But when I continue, the view shows location.latitude and location.longitude fine. Therefore, I know that it is populated.

For completeness, I will also include the GetLocationByAddress function, which does the same, if I put a breakpoint somewhere after waiting, I cannot check the variables (even the deserialized list!).

public async Task<Geolocation> GetLocationByAddress(string address)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://maps.googleapis.com/maps/api/geocode/json");
                var request = new HttpRequestMessage(HttpMethod.Get, "?address=" + WebUtility.UrlEncode(address) + "&key=...");
                var response = await client.SendAsync(request);
                var contents = await response.Content.ReadAsStringAsync();
                var locationResult = JsonConvert.DeserializeObject<GoogleLocationResult>(contents);
                if (locationResult.status == "OK")
                {
                    var result = locationResult.results.First().geometry.location;
                    return new Geolocation
                    {
                        Latitude = result.lat,
                        Longitude = result.lng
                    };
                }
                else
                {
                    return null;
                }
            }
        }
+4
source share
2 answers

Well, after I lost all day with this problem, I finally found the source of the problem, as well as the solution ... In my case, the problem arose after updating my project to use .net core 1.1 Preview 1, following the instructions below: Link to the MSFT.NET Blog

The problem was caused by this line of code in the project.json file:

"buildOptions": {
  "debugType": "portable",   <---- THIS
  "preserveCompilationContext": true,
  "emitEntryPoint": true
}

"debugType" "full", .

, - !

+5

. , , Task. GetLocation ( , HTTP-, , , ). , , , . , , GetLocation.

, , null ref , , Google Maps, .

-2

Source: https://habr.com/ru/post/1654178/


All Articles