简体   繁体   中英

Incorrect value while debugging in Visual Studio 2015

Assume we have sample code (VS2015, WinForms, .Net 4.6.1):

List<int> items = new List<int>();
private async Task test(int id)
{
    id = 1;
    int id_real = id;

    int index = items.FindIndex(x => x == id);
}

private async void button1_Click(object sender, EventArgs e)
{
    await test(0);
}

Now "the feature": 在此输入图像描述

How is that possible? The interesting part - it is only Visual Studio watcher problem, runtime result remains correct.

For now I know it is only happens in VS2015, and cause of this behaviour - the last string in test method.

Please enable "Use Managed Compatibility Mode" under TOOLS->Options->Debugging, and then re-debug your app, I think you would get the correct result in debugger windows as the VS2013 or VS2017.

在此输入图像描述

Updated:

I also reported this issue to the connect report even if we could resolve this issue:

https://connect.microsoft.com/VisualStudio/feedbackdetail/view/3135000/incorrect-value-while-debugging-in-visual-studio-2015

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM