Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2019: Error pop-up appears: "To prevent an unsafe abort when evaluating the function..."

I am facing an issue with Visual Studio 2019 (version 16.3.8), when starting an ASP.NET Core 3 WebApi project.

After clicking OK the project starts and runs without any issue. However the pop-up keeps nagging me every time I start my solution.

  1. How can I stop showing it?
  2. What is it trying to tell me anyway?

enter image description here

like image 606
Matthias Güntert Avatar asked Nov 08 '19 10:11

Matthias Güntert


2 Answers

There seems to be two possible solutions to this, that at least worked for me being on Visual Studio 2019.

Solution

Goto Tools => Options => Debugging => General and then either enable Use Managed Compatibility Mode (thanks to Nan Yu) or disable Enable property evaluation and other implicit function calls.

The second solution faces the drawback that when being in break mode, we have to manually hit refresh on the locals window to see a variables content.

Background

The message is telling us, that our system state may get changed when being in break mode due to implicit property evalution.

By default, we tell Visual Studio debugger to try and evaluate properties implicitly. This of course requires running code while we are braked, and not only display memory content. Running code, might potentially change the state of the system, which is not always what we want. For example, I might be increasing a counter every time the property is accessed, which means that when the debugger will try to evaluate the property, my code will run, the counter will be incremented, and my system state is changed, even though I am braked.

https://blogs.msdn.microsoft.com/eliofek/2012/12/12/why-do-we-get-the-function-evaluation-requires-all-threads-to-run/

like image 121
Matthias Güntert Avatar answered Sep 21 '22 12:09

Matthias Güntert


I had some variables in my watch window that was causing this error popup to happen. Just remove them from your watch window and the error popup should no longer display.

like image 34
jman Avatar answered Sep 19 '22 12:09

jman