I'm using Visual Studio 2022 Community edition. I have a breakpoint set inside my method used in the Select method of LINQ. When debugging my console application debugger enters a break state but does not show that it stopped on the execution of my method. The debugger goes into break mode but displays a message
Your app has entered a break state, but no code is currently executing that is supported by the selected debug engine (e.g. only native runtime code is executing).
Minimal reproduction code:
static void Main(string[] args)
{
var array = new string[] { "A X", "A Z"};
var result = array.Select(x => Score(x)).Sum();
Console.WriteLine(result);
}
public static int Score(string text)
{
return text.Length * 2;
}
The breakpoint is set in Score
method.
I expect that debugger would show that it stopped during the execution of my method. When I change the LINQ Sum
method to Count
method debugging worked correctly and recognized that breakpoint was in my method.
Expected debugger behavior result with method changed to Count
I think that it is some code optimization issue. I tried the following solutions from the internet and they did not help:
- Disabling code optimization in Project -> right click -> Properties -> Build -> General -> Optimize Code
- Disabling "Enable Just My Code" in Tools -> Options -> Debugging -> General -> Enable Just My Code
Does anybody know how I can fix such debugger behavior?
CodePudding user response:
I tried this code in .net framework 4.7 project it works well. But have this problem in .net 7.
It seems no setting to fix this problem in my test. And the definition of Method Sum in .net framework 4.7 looks same as it in .net 7.
I'm not sure if it's a problem caused by upgrading from .net framework to .net.
As Roman Ryzhiy said, you can temporarily fix this by adding .ToList() or .ToArray() to your code. And then you can report this problem on dc.