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.

当前回答

如果你在编译时启用了优化,那么许多变量将被删除;例如:

SomeType value = GetValue();
DoSomething(value);

在这里,局部变量值通常会被删除,而是保留在堆栈上的值-有点像你写的:

DoSomething(GetValue());

同样,如果一个返回值根本没有被使用,那么它将通过“pop”被删除(而不是通过“stloc”存储在本地,并且再次;本地将不存在)。

正因为如此,在这样的构建中,调试器无法获得value的当前值,因为它不存在——它只存在于GetValue()和DoSomething(…)之间的短暂瞬间。

所以;如果你想调试…不要使用发布版本!或者至少在调试时禁用优化。

其他回答

在visual Studio 2017中 去调试->选项,然后检查调试->通用-> 选中这个选项

我也有同样的问题。尝试以上所有方法,发现我还必须删除{PROJECT_ROOT}\bin\Release\netcoreapp2.2和{PROJECT_ROOT}\obj\Release\netcoreapp2.2内的所有内容。它肯定与发布有关,因为虽然我在我的Azure Web应用程序上使用部署工具/ bitbucket,但我确实尝试了Build >> Publish >> Publish to Azure,因为我想检查哪些文件实际部署了。

我也遇到过同样的问题,我的解决方案是将解决方案配置从发布更改为调试。希望能有所帮助

在Visual Studio 2012中:

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

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.