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

試著忘記壹切 提交于 2021-01-02 18:07:42

问题


I'm trying to debug the Antiforgery code in the ASP.NET Core 5 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

How can I force the code to not be optimized?

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


回答1:


After adding the Antiforgery source code project to my solution, rather than add a project reference to the .csproj file, I had to reference the dll in C:\aspnetcore\artifacts\bin\Microsoft.AspNetCore.Antiforgery\Debug\net5.0.

I can now view the values of local vars in the Watch window.



来源:https://stackoverflow.com/questions/65264454/how-to-force-asp-net-core-5-source-code-to-not-be-optimized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!