asp.net-mvc - Visual Studio 2015 异步变量未显示在调试器中

标签 asp.net-mvc visual-studio-2015 asp.net-core

我有一个 .NET Core ASP.NET MVC 6 应用程序,我确信 Visual Studio 中存在错误。如果我在await语句之后放置一个断点,该对象不会显示在局部变量中,并且我无法将鼠标悬停在上面进行检查。但如果我使用该变量,它仍然可以正常工作,并且它肯定已填充。

就这么简单:

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

如果我将断点放在 return 语句上,我将无法检查位置。它没有出现在任何地方。我什至可以删除等待并将 .Result 放在最后,但仍然没有显示。但是当我继续时, View 显示 location.latitude 和 location.longitude 很好。所以我知道它正在被填充。

为了完整起见,我还将包含 GetLocationByAddress 函数,该函数执行相同的操作,如果我在等待之后的任何位置放置断点,我将无法检查变量(甚至无法检查反序列化列表!)。

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;
                }
            }
        }

最佳答案

好吧,在这个问题上迷失了一整天后,我终于找到了问题的根源以及解决方案...... 就我而言,按照此处所示的步骤更新我的项目以使用 .net core 1.1 Preview 1 后,问题就开始了:Link to MSFT .NET Blog

问题是由project.json文件中的这行代码引起的:

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

将“debugType”设置为“full”后,等待的变量在调试时再次开始显示。

希望对大家有帮助!

关于asp.net-mvc - Visual Studio 2015 异步变量未显示在调试器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39419760/

相关文章:

html - 如何让整个 DIV 可以单击并重定向到下一页

asp.net-mvc - 使用 Kendo MVC Grid 和其他元素提交表单

ios - Xamarin 无法将 iOS 应用程序部署到 iOS 设备

c++ - Visual Studio 2015,C++ 项目, fatal error c1510

asp.net - 多个身份验证中间件 ASP.NET Core

asp.net-mvc - 覆盖个人用户帐户中的 AccountController

c# - ASP.NET Core Entity Framework Core 找不到 IndexAttribute

javascript - 如何检查所选行是否具有特定的联系人头衔?

javascript - jQuery 发布请求(不是 AJAX)

c - VS2015 中 C 代码中的无作用域枚举