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.

当前回答

对于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.

对于那些在调试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/

在Visual Studio 2012中:

打开项目属性->调试->取消选中“启用Visual Studio托管进程”

检查您的AssemblyInfo文件中是否有Debuggable属性。如果存在,则删除它并重新构建解决方案,以查看本地变量是否可用。

我的可调试属性被设置为:DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints,根据这篇MSDN文章,它告诉JIT编译器使用优化。我从我的AssemblyInfo.cs文件中删除了这一行,本地变量就可用了。

转到“项目属性”,在“构建”下确保“优化代码”复选框未选中。

此外,在高级选项(在构建选项卡下)中将“调试信息”下拉菜单设置为“完全”。