visual-studio-2019asp.net-core-3.0

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


Solution

  • 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/