C# 应用程序通过调试运行,但并非没有
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/738327/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# app runs with debugging, but not without
提问by Malfist
I'm running a (mostly) single threaded program (there's a main thread that does everything, the others only read stuff). I can get the application to run fine in VS2008 after a minor change (I changed the text of a form, and tab order of another form), but I can no longer get it to work outside of the debugger. Does anyone know what would cause this?
我正在运行一个(主要是)单线程程序(有一个主线程可以完成所有工作,其他线程只读取内容)。稍作改动后,我可以让应用程序在 VS2008 中正常运行(我更改了一个表单的文本和另一个表单的 Tab 键顺序),但我无法再让它在调试器之外工作。有谁知道这会导致什么?
Clarification:Release mode, launched with debugger (F5) works. Debug mode, lanuched with debugger (F5) works. Debug executable, or release executable launched outside of VS or with Ctrl+F5 fail.
说明:使用调试器 (F5) 启动的发布模式有效。调试模式,启动调试器 (F5) 工作。调试可执行文件或发布在 VS 外部启动的可执行文件或使用 Ctrl+F5 失败。
It uses Microsoft's Virtual Earth 3D, and it seems to crash just when the 'ring of hope' (loading ring) is about to complete.
它使用微软的Virtual Earth 3D,似乎就在“希望之环”(加载环)即将完成时崩溃。
Event logsays: ".NET Runtime version 2.0.50727.3053 - Fatal Execution Engine Error (000006427F44AA6E) (80131506)"
事件日志显示:“.NET 运行时版本 2.0.50727.3053 - 致命执行引擎错误 (000006427F44AA6E) (80131506)”
Culprit:this line:
罪魁祸首:这一行:
this.loader = PlugInLoader.CreateLoader(this.globeControl.Host);
Causes it to fail. However, the form that was working uses the exact same line without an issue. This line is nesseccary for the program to function. I have no idea what it's doing.
导致它失败。但是,正在工作的表单使用完全相同的行没有问题。这一行是程序运行所必需的。我不知道它在做什么。
Another Leadthe error seems to be inside the .NET framework. Application worked on another machine, attempting reinstall. Update:didn't make a difference, although when I repaired VS it kept telling me Visual Studio was crashing even though I wasn't running it.
另一个导致错误的原因似乎是在 .NET 框架内。应用程序在另一台机器上运行,正在尝试重新安装。更新:没有什么区别,虽然当我修复 VS 时,它一直告诉我 Visual Studio 崩溃了,即使我没有运行它。
ErrorWhen I launch the program after a couple minutes I get: Application has generated an exception that could not be handled.
错误当我在几分钟后启动程序时,我得到:应用程序生成了一个无法处理的异常。
Proccess ID=0x9CC (2508), Thread ID =0xF0C(3852).
进程 ID=0x9CC (2508),线程 ID =0xF0C(3852)。
Click OK to terminate the application.
Click CANCEL to debug the application.
单击确定终止应用程序。
单击取消以调试应用程序。
The disassembly is bizarre:
拆解很奇怪:
0000000077EF2A90 int 3
0000000077EF2A91 int 3
0000000077EF2A92 int 3
0000000077EF2A93 int 3
0000000077EF2A94 int 3
0000000077EF2A95 int 3
0000000077EF2A96 xchg ax,ax
0000000077EF2A9A xchg ax,ax
0000000077EF2A9E xchg ax,ax
0000000077EF2AA0 int 3 <-- Crashes here
0000000077EF2AA1 ret
It repeats that same code block several times (minus on ax exchanging with itself)
它多次重复相同的代码块(减去与自身交换的斧头)
Besides my computer, it has worked on every machine I've tested it on, except for a VM on my machine which won't install the .NET framework because setup downloads 0 bytes out of 0 bytes for the framework)...lovely windows.
除了我的电脑之外,它在我测试过的每台机器上都可以运行,除了我机器上的虚拟机不会安装 .NET 框架,因为安装程序会下载框架的 0 字节中的 0 字节)......可爱视窗。
采纳答案by Malfist
I fixed it, the .NET 2.0 Framework was corrupt and when I reinstalled it, everything magically started working again.
我修复了它,.NET 2.0 框架已损坏,当我重新安装它时,一切都神奇地重新开始工作。
回答by George Mauer
回答by JP Alioto
Hereis a support article with that error. Does that apply?
这是一篇包含该错误的支持文章。这适用吗?
Perhaps the debugger is eating an excaption the VE3D API is throwing. In VS, do a ctrl+alt+e and change it to break whenever any exception is thrown. This can be tedius b/c it will break on all your try catch blocks, but it might give you some information.
也许调试器正在吃 VE3D API 抛出的一个 excaption。在 VS 中,执行 ctrl+alt+e 并将其更改为在抛出任何异常时中断。这可能是乏味的 b/c 它会在你所有的 try catch 块上中断,但它可能会给你一些信息。
Hereis some info. about that PlugInLoader. It seems to imply it must be called from the FirstFrameRendered eventhandler. Perhaps one of your forms is doing that and one not?
这是一些信息。关于那个 PlugInLoader。这似乎暗示它必须从 FirstFrameRendered 事件处理程序中调用。也许您的一种形式正在这样做而另一种则没有?
回答by C. Ross
I've had similar issues where timing conflicts were causing the failure, and my debugging (breakpoints and stepping through the code) forced the code to run in the correct order.
我遇到过类似的问题,其中时序冲突导致失败,我的调试(断点和单步执行代码)迫使代码以正确的顺序运行。
回答by Mladen Mihajlovic
Try take off optimizations from the Release build (in the project settings) and see if that helps.
尝试从发布版本(在项目设置中)取消优化,看看是否有帮助。
回答by galets
I cannot tell you what exactly the problem is, but here's what you could do to get a clue what's really happening. I assume you're using VS2008 or 2005.
我无法告诉您问题究竟是什么,但您可以通过以下方法了解实际情况。我假设您使用的是 VS2008 或 2005。
- Switch to release mode
- Go to Debug\Exceptions, and mark all "Thrown" exceptions, like illustrated here: http://vvcap.net/db/JbWS_tzy2IpBoI7R7amm.htp
- Run executable in debugger, ignore the warnings from VS that there's no debug info
- 切换到释放模式
- 转到 Debug\Exceptions,并标记所有“抛出”异常,如下所示:http: //vvcap.net/db/JbWS_tzy2IpBoI7R7amm.htp
- 在调试器中运行可执行文件,忽略 VS 没有调试信息的警告
It does seem that there's a win32 exception thrown some time during execution, but this way or another, you will get one or more messages from debugger explaining what kind of exception happened and where. In most cases those messages make it pretty clear what exactly went wrong
似乎确实在执行过程中的某个时间抛出了 win32 异常,但是通过这种方式或其他方式,您将收到一条或多条来自调试器的消息,说明发生了何种异常以及发生在何处。在大多数情况下,这些消息非常清楚究竟出了什么问题
EDIT: One thing I forgot to mention is that unmanaged debugging must also be turned on, such like here (when you start program directly from IDE)or here (when you attach to running process)
编辑:我忘记提及的一件事是非托管调试也必须打开,例如here(当您直接从IDE启动程序时)或here(当您附加到正在运行的进程时)
回答by Mladen Mihajlovic
One thing left I think is to use WinDbg to try and debug it. Here are some links on how to use it:
我认为剩下的一件事是使用 WinDbg 来尝试调试它。以下是有关如何使用它的一些链接:
- http://www.codeproject.com/KB/debug/windbg_part1.aspx
- http://blogs.msdn.com/johan/archive/2007/11/13/getting-started-with-windbg-part-i.aspx
- http://blogs.msdn.com/tess/(good blog about debugging in general in windbg)
- http://www.codeproject.com/KB/debug/windbg_part1.aspx
- http://blogs.msdn.com/johan/archive/2007/11/13/getting-started-with-windbg-part-i.aspx
- http://blogs.msdn.com/tess/(关于在windbg中进行一般调试的好博客)
Thinking about it, it could also be some service or something that's clashing. Try stopping all unneeded services and closing unneeded programs (including startup ones) and see what happens then.
想想看,它也可能是一些服务或发生冲突的东西。尝试停止所有不需要的服务并关闭不需要的程序(包括启动程序),然后看看会发生什么。
回答by Gomes
we found and fixed this issue with MSFT, we faced this problem with VSTO development. Apply the following patch from MSFT.
我们在 MSFT 中发现并解决了这个问题,我们在 VSTO 开发中遇到了这个问题。从 MSFT 应用以下补丁。
http://support.microsoft.com/kb/975954
http://support.microsoft.com/kb/975954
回答by Christoph Mei?ner
I once had a similar problem with exactly the same behaviourusing a plug-in-system. When loading a plug-in from a MarshalByRef
-object (see example code below), it seems as if .NET creates a new AppDomain or Context for the loaded assembly. (Can anyone confirm this? I've not found any source regarding this.)
我曾经遇到过类似的问题,使用插件系统的行为完全相同。从MarshalByRef
-object加载插件时(请参阅下面的示例代码),似乎 .NET 为加载的程序集创建了一个新的 AppDomain 或 Context。(有人可以证实这一点吗?我没有找到任何有关此的消息来源。)
public class ProxyAssemblyLoader : MarshalByRefObject {
public Assembly GetAssembly(string path) {
return Assembly.LoadFrom(path);
}
}
Furthermore in my case the plug-in loads a different version of the mscorlib
. (My app is CLR2 and the loaded is CLR4) Afterwards I used the plug-in by reflection and tried to access a value of the new mscorlib, which was loaded from the other application domain. Usually both should be usable because the mscorlib is a commonly used assembly and only loaded once (see Global Assembly Cache). But it seemsas if this is not the case. But in general Microsoft advises to avoidthat.
此外,在我的情况下,插件加载了不同版本的mscorlib
. (我的应用程序是CLR2,加载的是CLR4)之后我通过反射使用了插件并尝试访问从其他应用程序域加载的新mscorlib的值。通常两者都应该可用,因为 mscorlib 是一个常用程序集并且只加载一次(请参阅全局程序集缓存)。但似乎并非如此。但总的来说,微软建议避免这种情况。
I've not exactly figured out what the problem was, but I figured out the call that causes the application to crash without any hint. Why without any hint?It crashed without any hint, because the thrown exception was only available in "the other" appdomain and not available for the main/default app domain.
我还没有完全弄清楚问题是什么,但我发现了导致应用程序崩溃的调用,而没有任何提示。为什么没有提示?它在没有任何提示的情况下崩溃了,因为抛出的异常仅在“其他”应用程序域中可用,而对主/默认应用程序域不可用。
The taken action was just implicit copying the value of another appdomains assembly to a local untyped value (object
) in the default appdomain. This was enough to get a type identity mismatch error due different versions of the assembly. It seems as if Visual Studio could handle it, but if the application runs standalone it crashes.
所采取的操作只是将另一个 appdomains 程序集的值隐式复制到object
默认 appdomain 中的本地无类型值 ( )。由于程序集的不同版本,这足以导致类型标识不匹配错误。似乎 Visual Studio 可以处理它,但如果应用程序独立运行,它就会崩溃。
This may also explains why you needed to reinstall your .NET. Maybe your installed .NET-Framework was a beta or something like that, which contained a minor difference.
这也可以解释为什么您需要重新安装 .NET。也许您安装的 .NET-Framework 是测试版或类似的东西,其中包含细微的差异。
In conclusion some general solutions for the problem could be:
总之,该问题的一些一般解决方案可能是:
- Avoid using different versions of assemblies with different versions of the same type.
- In other cases may try to load both assemblies inside the same appdomain. (As far as possible regarding the probing context.)
- A solution for cross appdomain communication could be serializationof the values.
- (Make sure that the correct .NET-Framework Non-Beta Version is installed.)
回答by Kirk Herron
I had the exact same issue with one of my console applications. I determined that it was my antivirus (Avast) that was causing the issue.
我的控制台应用程序之一遇到了完全相同的问题。我确定是我的防病毒软件 (Avast) 导致了问题。
Add the BIN
folder to the exclusion list and disable "DeepScreen".
Then rebuild the project and try again!
将该BIN
文件夹添加到排除列表并禁用“DeepScreen”。然后重建项目并重试!