加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 09:56:22 所属栏目:asp.Net 来源:网络整理
导读:我有一个.NET Core ASP.NET MVC 6应用程序,我确信它是Visual Studio中的一个错误.如果我在await语句后面放置一个断点,那么该对象不会显示在Locals中,并且我无法鼠标移动来检查.但是,如果我使用变量,它仍然可以正常工作,并且它确实填充. 像这样简单: public
我有一个.NET Core ASP.NET MVC 6应用程序,我确信它是Visual Studio中的一个错误.如果我在await语句后面放置一个断点,那么该对象不会显示在Locals中,并且我无法鼠标移动来检查.但是,如果我使用变量,它仍然可以正常工作,并且它确实填充.

像这样简单:

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

如果我将断点放在return语句上,我就无法检查位置.它不会出现在任何地方.我甚至可以删除await&放置一个.结果,但仍然没有显示.但是当我继续时,视图会显示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核心1.1预览1之后,问题已经开始,遵循此处显示的步骤: Link to MSFT .NET Blog

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

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

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

希望它对某人有帮助!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读