'How to force ASP.NET Core source code to not be optimized

I'm trying to debug the Antiforgery code in the ASP.NET Core framework.

I have built the code successfully using the instructions in https://github.com/dotnet/aspnetcore/blob/master/docs/BuildFromSource.md using the Debug configuration.

I have added the source code project to my test project and referenced it.

I've checked that the Configuration is set to Debug.

I've made sure that "Suppress JIT Optimizations" has been checked.

"Optimize Code" in Project Properties -> Build, is unchecked for both projects.

"Debug Info" dropdown has been set to "Full" in the Advanced Options (Under Build tab) for both projects.

However when I hit the breakpoint in DefaultAntiforgeryTokenSerializer.Serialize(), it gives me this error when viewing the method's local vars in the Watch window:

Cannot obtain value of local or argument as it is not available at this instruction pointer, possibly because it has been optimized away

enter image description here

How can I force the code to not be optimized?

I'm using Visual Studio Enterprise 2019 v16.8.3.



Solution 1:[1]

Full instructions at https://github.com/dotnet/AspNetCore.Docs/issues/4155

  • Un-check Enable Just My Code in Tools -> Options -> Debugging -> General
  • Enable Microsoft Symbol Servers in Tool -> Options -> Debugging -> Symbols

Full maintained instructions by Microsoft at https://docs.microsoft.com/en-us/aspnet/core/test/debug-aspnetcore-source

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RickAndMSFT