Visual Studio 2010在不安全块中杀死函数的一个参数中的数据(没有其他词)。 是什么导致了这个错误?调试器显示以下消息。

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

当前回答

对于那些在调试Azure网站的web应用程序时遇到此问题的人,还有一个额外的答案:

例如,当从GitHub部署时,代码在默认优化的Azure服务器中编译。

通过将SCM_BUILD_ARGS设置为/p:Configuration=Debug,我告诉服务器以可调试的方式进行编译

但还有更多的选择。看到这个: http://azure.microsoft.com/blog/2014/05/08/introduction-to-remote-debugging-on-azure-web-sites-part-3-multi-instance-environment-and-git/

其他回答

对于web应用程序,还有一个重要的问题,那就是在应用程序发布过程中选择正确的配置。

你可以在调试模式下构建你的应用,但它可能发生在你以发布模式发布它,默认情况下优化代码,但IDE可能会误导你,因为它显示调试模式,而发布的代码是在发布模式。 你可以在下面的快照中看到详细信息:

I found that I had the same problem when I was running a project and debugging by attaching to an IIS process. I also was running in Debug mode with optimizations turned off. While I thought the code compiled fine, when I detached and tried to compile, one of the references was not found. This was due to another developer here that made modifications and changed the location of the reference. The reference did not show up with the alert symbol, so I thought everything was fine until I did the compilation. Once fixing the reference and running again it worked.

关于“优化代码”属性未选中的问题,但代码仍然编译为优化:在尝试了所有东西后,最后帮助我的是在同一设置页面上检查“启用非托管代码调试”复选框(项目属性-调试)。它与代码优化没有直接关系,但是启用这个功能后,VS不再优化我的库,我可以调试。

以我为例,我正在开发一个web api项目,尽管该项目被正确地设置为完全调试,但每当我连接到我试图调试的IIS进程时,我仍然会看到这个错误。然后我意识到发布概要文件被设置为使用发布配置。所以,如果你正在使用dotnet web api项目的“发布”功能,还有一个地方要检查你的发布配置文件。

当我面临同样的问题时,我只需要在重建之前清理我的解决方案。这帮我解决了问题。