如何纠正堆栈下溢错误 [英] How to correct Stack UNDERflow error

查看:31
本文介绍了如何纠正堆栈下溢错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我正在使用优化编译的应用程序(Visual Studio 2015)中尝试执行特定过程时,我收到 InvalidProgramException 异常.我使用 PEVerify 来查看它对问题的描述,它告诉我Method[offset 0x00000351] Stack underflow".

I get an InvalidProgramException when trying to execute a particular procedure in an application I am working on when it has been compiled with optimizations (Visual Studio 2015). I used PEVerify to see what it says about the problem, and it tells me "Method[offset 0x00000351] Stack underflow".

显然我可以通过关闭优化来解决这个问题,但这不是最佳解决方案,因为等待 MS 在下一个版本中修复导致它的任何错误.

Obviously I can fix the problem by turning optimizations off, but that is a less than optimal solution, as is waiting for MS to fix whatever bug causes it in the next version.

如何修复堆栈下溢错误?如果我不得不猜测,我会说这可能与这个类大约有 18k 行的事实有关,但我对此无能为力......

What can I do to fix a stack underflow error? If I had to guess I'd say that it's probably related to the fact that this class is somewhere around 18k lines, but there's not a lot I can do about that...

编辑:明确地说,我不希望得到删除 6276 和 6277 行"这样的答案,我正在寻找的是解决此类问题的一般策略在.net中.类似于这个 ActionScript 问题的答案:如何调试运行时堆栈下溢错误?,特定于 .net 的除外.我发布此信息是为了让下一个遇到此类问题的人有一个起点,他们可能会尝试解决此问题.

Edit: Just to be clear, I don't expect an answer along the lines of "delete lines 6276 and 6277", what I am looking for is general strategies for troubleshooting this type of problem in .net. Something like the answers to this ActionScript question: How to debug a runtime stack underflow error?, except specific to .net. I am posting this so that the next person that has this type of problem will have a starting point for what they might try to work around this issue.

推荐答案

好的,首先无效程序异常表示 编译器有问题,而不是您的应用程序.这意味着您可以在不运行应用程序的情况下进行测试以查看问题是否仍然存在(或已演变为不同的问题).一旦您看到此错误,您就脱离了正常的调试场景——您没有做错任何事情,因此无法通过检查变量并查看您做错的地方来找到或修复问题.

Ok, first off an Invalid Program Exception indicates something is wrong with the compiler, not your application. This means that you can test to see if the problem still exists (or has morphed into a different problem) without running your application. Once you see this error you are out of the normal debugging scenario -- you haven't done something wrong, and thus can't find or fix the problem by examing variables and seeing where you are doing the wrong thing.

第一个怀疑可能是优化——没有优化的构建,看看你的 exe 是否仍然一团糟.如果是这样,您可以考虑关闭优化,这是一种充分的解决方法.您甚至可以使用 System.Runtime.CompilerServices.Methodimpl(methodimploptions.nooptimization) 为特定方法关闭它.

The first suspect is probably optimizations--build without optimizations and see if your exe is still messed up. If so, you may consider turning optimizations off a sufficient workaround. You might even be able to use the System.Runtime.CompilerServices.Methodimpl(methodimploptions.nooptimization) to turn it off for a specific method.

如果没有,或者没有任何改变,您想找出触发该错误的原因,一个很好的起点是 Pverify.对编译后的 exe 运行它,它会列出所有存在错误代码的地方,即使它是一个未调用的方法.

If not, or that doesn't change anything, you want to find out what is triggering the bug, and a good staring point for that is Peverify. Run it against the compiled exe and it will list all of the places where bad code exists, even if it is an uncalled method.

由于这是一个编译器错误,因此您无法单步执行某个方法来准确查看哪一行已关闭.这有它的好处——你不必有一个有效的(或者正如我上面所说的,可达的)方法.只要代码编译通过,它要么有问题,要么没有问题,因此您可以通过注释或删除导致问题的方法中的行来找到有问题的行.

Since this is a compiler bug, you can't step through a method to see exactly which line is off. That has it's upside -- you don't have to have a functioning (or as I said above, reachable) method. As long as the code compiles, it will either have the problem or not, so you can find the offending line(s) by commenting out or deleting lines in the method that is causing problems.

这篇关于如何纠正堆栈下溢错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆