应用程序因“.NET 运行时内部错误”而崩溃
我们有一个针对 .NET 4.0 编写的应用程序,该应用程序在周末崩溃了,并将以下消息放入事件日志中:
应用程序:PnrRetrieverService.exe 框架版本:v4.0.30319
由于内部错误,进程被终止。 .NET 运行时位于 IP 791F9AAA (79140000),退出代码为 80131506。
它位于 Windows Server 2003 R2 标准版盒子上。谷歌搜索这个错误没有发现任何相关的信息。例如,这不会发生在 VS Studio 中,而是发生在生产环境中;当服务最终重新启动时,它没有遇到进一步的问题。
如何诊断 .NET 运行时中的错误?
We have an application written against .NET 4.0 which over the weekend crashed, putting the following message into the event log:
Application: PnrRetrieverService.exe Framework Version: v4.0.30319
Description: The process was terminated due to an internal error in
the .NET Runtime at IP 791F9AAA (79140000) with exit code 80131506.
This is on a Windows Server 2003 R2 Standard Edition box. Googling this error hasn't turned up anything pertinent. For example, this isn't occurring in VS Studio, but instead on a production box; when the service was eventually restarted, it experienced no further problems.
How does one go about diagnosing a bug in the .NET Runtime?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(19)
就我而言,问题与“在经典 asp.net 项目中引用 .NET 标准库”和这两个问题
https://github.com/dotnet/standard/issues/873
https://github.com/App-vNext/Polly/issues/628
并降级到 Polly v6 足以解决这个问题
In my case the problem was related to "Referencing .NET standard library in classic asp.net projects" and these two issues
https://github.com/dotnet/standard/issues/873
https://github.com/App-vNext/Polly/issues/628
and downgrading to Polly v6 was enough to workaround it
在我的电脑从 Windows 更新自动生成更新的 .NET dll 后,我就发生了这种情况。 ngen 期间出现问题,许多使用 .NET 的东西(包括 powershell 和 Hyper-V MMC GUI)很快就会崩溃。
事件查看器日志显示哪个版本的 .NET 运行时出现问题。就我而言,它是 v4.0.30319。指令指针为 8 个字节,意味着它作为 64 位应用程序运行。
修复方法是强制重新生成所有程序集。对于受影响的框架,我打开了管理员命令提示符,导航到
C:\Windows\Microsoft.NET\Framework64\v4.0.30319
并运行
ngen.exe update /force
(令人惊讶的是,我在任何地方都找不到
/force
选项的官方文档,但互联网上的许多地方引用它来使所有本机图像无效。)几分钟后,它完成了,并且 powershell Hyper-V MMC GUI 再次工作。
修复后分析显示,之前有一个 DLL 已被生成到具有不同内容的不同位置,我猜这就是罪魁祸首。
This happened to me after my PC automatically ngen'ed updated .NET dlls from a windows update. Something went wrong during the ngen, and many things that use .NET, including powershell and the Hyper-V MMC GUI, would quickly crash.
Event viewer logs showed which version of the .NET runtime iwas having the issue. In my case, it was v4.0.30319. The instruction pointer being 8 bytes meant it was running as a 64-bit app.
The fix was to force re-ngen of all assemblies. For my affected framework, I opened and administrator command prompt, navigated to
C:\Windows\Microsoft.NET\Framework64\v4.0.30319
and ran
ngen.exe update /force
(Surprisingly, I could not find official documentation for the
/force
option anywhere, but a number of places on the internet reference it for invalidating all native images.)A few minutes later, it completed, and powershell and the Hyper-V MMC GUI were working again.
Post-fix analysis revealed a single DLL had previously ngen'ed to a different location with different content, which I'm guessing was the culprit.
就我而言,登录 SAP Business One 9.1 应用程序时会发生此错误。在 Windows 事件中,除了 OP 报告的错误事件之外,我还可以找到另一个错误事件:
机器运行 Windows 8.1,安装了 .NET Framework 4.0,但没有 4.5 版本。从互联网上看来,这也可能是 .NET 4 中的一个错误,因此我尝试安装 .NET Framework 4.5.2 并解决了该问题。
In my case this error occured when logging in SAP Business One 9.1 application. In Windows events I could find also another error event in addition to the one reported by the OP:
The machine run Windows 8.1, with .NET Framework 4.0 installed and without the 4.5 version. As it seemed from the internet that it could be also a bug in .NET 4, I tried installing .NET Framework 4.5.2 and I solved the issue.
框架版本:v4.0.30319
描述:由于未处理的异常,进程被终止。
异常信息:System.Reflection.TargetInitationException
我遇到过此错误,应用程序在某些 PC 上运行良好,而在某些 PC 上却出现上述错误。我卸载了 Framework 4.5 并重新安装,这解决了我的问题。
欢呼。
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Reflection.TargetInvocationException
I have faced this Error, Application was working fine on some PCs and on some PCs giving the above error. I uninstall the Framework 4.5 and re-install this resolved my problem.
Cheer.
我从来不明白为什么这会发生在我身上。对于我的一个应用程序来说,它始终可以重现,但在重新启动后就消失了。
我正在运行带有 .net-4.8 的 Windows 2004 Build 19582.1001(Insider Preview),如果这是由于硬件内存错误等原因造成的,我也不会感到惊讶。另外,我的应用程序确实加载了一些非托管代码并对其进行了初始化,因此我无法证明崩溃不是由此而来。
I never figured out why this was happening for me. It was consistently reproducible for one of my applications, but went away after simply rebooting.
I am running Windows 2004 Build 19582.1001 (Insider Preview) with .net-4.8 and I also would not be surprised if this were due to something like a hardware memory error. Also, my application does load some unmanaged code and initialize it, so I can’t prove that the crash didn’t come from that.
我在安装 SQL Server 2017 时在 Windows 2016 上遇到了同样的问题。错误是
“ScenarionEngine.exe 因“.NET 运行时中的内部错误”而崩溃”
首先检查 Microsoft .NET Framework 版本是否为 4.5,然后升级到最新版本。目前它是 Microsoft .NET Framework 4.8。如果这对您不起作用,请尝试下一步
:请卸载 KB4486129,然后下载 Microsoft .NET Framework 4.8。同样的错误已为我解决。
I had same issue on Windows 2016 while installing SQL server 2017. Error was
"ScenarionEngine.exe Crashes With "Internal Error In The .NET Runtime"
First check the Microsoft .NET Framework version if it is 4.5 then upgrade is to latest version. Currently it is Microsoft .NET Framework 4.8. If this not work for you then try the next step.
Next Step: Please uninstall KB4486129, and then download the Microsoft .NET Framework 4.8. Same error has been resolved for me.
这是一个令人讨厌的问题,ExecutionEngineException。从 .NET 4.0 开始,此异常会立即终止程序。一般原因是垃圾收集堆的状态损坏。这又总是由非托管代码引起的。代码中引发此异常的确切位置没有帮助,损坏通常发生在检测到损坏之前。
找到造成这种情况的确切原因将很困难。检查您的服务可能使用的任何非托管代码。如果没有明显的候选者,则怀疑环境问题,行为不当的恶意软件扫描程序是臭名昭著的。如果重复效果很差,则怀疑硬件问题,例如软 RAM 错误。
That's a nasty one, ExecutionEngineException. Starting with .NET 4.0, this exception immediately terminates the program. The generic cause is corruption of the state of the garbage collected heap. Which in turn is invariably caused by unmanaged code. The exact location in code at which this exception is raised isn't helpful, the corruption usually occurred well before the damage is detected.
Finding the exact cause for this is going to be difficult. Review any unmanaged code your service might be using. Suspect environmental problems if there is no obvious candidate, misbehaving malware scanners are notorious. If it repeats very poorly then suspect hardware problems like soft RAM errors.
x64 .Net 4 上垃圾收集并发实现中的错误可能会导致此问题,如以下 Microsoft 知识库条目所述:
垃圾收集期间发生 ExecutionEngineException
您应该首先进行深入的小型转储探索,以确保问题发生在垃圾收集期间垃圾收集。
通常可以在事件日志中崩溃条目后面的 Windows 错误报告条目中找到小型转储位置。
然后,享受 WinDbg 的乐趣吧!
有关使用
配置元素禁用并发或(在 .NET 4 及更高版本中)后台垃圾收集的最新文档,可以在 此处。A bug in the concurrent implementation of the Garbage Collection on x64 .Net 4 can cause this as stated in the following microsoft KB entry:
ExecutionEngineException occurs during Garbage Collection
You should first make a deep minidump exploration to be sure that the problem occured during a Garbage collection.
The minidump location can usually be found in a Windows Error Reporting entry in the event log following the crash entry.
Then, have fun with WinDbg !
The latest documentation on the use of the
<gcConcurrent/>
configuration element, to disable concurrent or (in .NET 4 and later) background garbage collection, can be found here.我在 .NET 运行时遇到过“内部错误”,这些错误是由我的代码中的错误引起的;不要认为仅仅因为它是 .NET 运行时中的“内部错误”,代码中就没有错误作为根本原因。在你责怪别人的代码之前,永远总是先责怪你自己的代码。
希望您有日志记录和异常/堆栈跟踪信息来指导您从哪里开始查找,或者您可以在崩溃之前重复系统的状态。
I've experienced "internal errors" in the .NET runtime that turned out to be caused by bugs in my code; don't think that just because it was an "internal error" in the .NET runtime that there isn't a bug in your code as the root cause. Always always always blame your own code before you blame someone else's.
Hopefully you have logging and exception/stack trace information to point you where to start looking, or that you can repeat the state of the system before the crash.
在我的 .NET 4 代码的最新版本的 WinXP 机器上也出现了同样的错误。检查了以前的版本 - 现在它们也崩溃了!好吧,所以这不是我:)。这里/上面的建议没有帮助。
最近(2018-05-09)同一问题的报告:应用程序崩溃,退出代码为 80131506。
根本原因仍然未知(机器没有更新并且几乎没有用),但是为我做的!
Had the same exact error on WinXP box with latest build of my .NET 4 code. Checked previous builds - now they crash too! Ok, so it's not me :). No suggestions here/above helped.
Much more recent (2018-05-09) report of the same problem: Application Crash with exit code 80131506.
Root cause is still unknown (machine is not being updated and has little use), but that did it for me!
对于那些从谷歌到达这里的人,我最终遇到了 这个问题,以及这个具体答案解决了我的问题。我已通过 support.microsoft.com 上的实时聊天联系 Microsoft 获取修补程序,他们向我发送了一个链接通过电子邮件发送至修补程序。
For those arriving here from google, I've eventually come across this SO question, and this specific answer solved my problem. I've contacted Microsoft for the hotfix through the live chat on support.microsoft.com and they sent me a link to the hotfix by email.
经过多年在许多应用程序中解决此问题后,Microsoft 似乎终于接受了它作为 .NET 4 CLR 中导致这种情况发生的错误。 http://support.microsoft.com/kb/2640103。
我之前曾通过强制垃圾收集器以服务器模式运行(app.config 中的 gcServerenabled="true")来“修复”它,如 Think Before Coding 链接的 Microsoft 文章中所述。这实质上会强制应用程序中的所有线程在收集期间暂停,从而消除其他线程访问 GC 操作的内存的可能性。我很高兴地发现,多年来我在代码或其他第 3 方非托管库中徒劳地寻找“错误”只是徒劳,因为错误存在于 Microsoft 的代码中,而不是我的代码中。
After years of wrestling with this issue in a number of applications, it appears that Microsoft has finally accepted it as a bug in .NET 4 CLR that causes this to occur. http://support.microsoft.com/kb/2640103.
I had previously been "fixing" it by forcing the garbage collector to run in server mode (gcServer enabled="true" in app.config) as described in the Microsoft article linked to by Think Before Coding. This in essence forces all threads in the application to pause during the collection removing the possibility of other threads accessing the memory being manipulated by the GC. I am happy to find that my years of searching in vain for a "bug" in my code or other 3rd party unmanaged libraries were only fruitless because the bug lay in Microsoft's code, not mine.
可能是并发 GC 的错误
http://support.microsoft.com/kb/2679415
Could be a bug with concurrent GC
http://support.microsoft.com/kb/2679415
就我而言,当磁盘空间耗尽且 .NET 无法在 Windows 虚拟内存中分配内存时,就会发生此异常。
在事件日志中,我看到此错误:
应用程序弹出窗口:Windows - 虚拟内存最小值太低:您的系统虚拟内存不足。 Windows 正在增加虚拟内存页面文件的大小。在此过程中,某些应用程序的内存请求可能会被拒绝。
和之前的错误:
C: 磁盘已达到或接近容量。您可能需要删除一些文件。
In my case this exception was occured when disk space was over and .NET can't allocate memory in Windows Virtual Memory.
In event log I saw this error:
Application popup: Windows - Virtual Memory Minimum Too Low : Your system is low on virtual memory. Windows is increasing the size of your virtual memory paging file. During this process, memory requests for some applications may be denied.
And previous error:
The C: disk is at or near capacity. You may need to delete some files.
每隔 5-10 分钟,我的应用程序池就会因该退出代码而崩溃。我不想破坏您对垃圾收集器的信任,但以下解决方案对我有用。
我添加了一个每分钟调用 GC.GetTotalMemory(true) 的作业。
我认为,出于某种原因,GC 不会足够频繁地自动检查我使用的大量一次性对象的内存。
Every 5-10 minutes my application pool kept crashing with this exit code. I do not want to ruin your trust of the Garbage Collector, but the following solution worked for me.
I added a Job that calls
GC.GetTotalMemory(true)
every minute.I suppose that, for some reason, the GC is not automatically inspecting the memory often enough for the high number of disposable objects that I use.
就我而言,问题是 C++/CLI 库,其中调用了 NtQuerySystemInformation;有时由于某种原因(在神秘的情况下),当它被调用时,CLR 堆被损坏并且应用程序崩溃了。
我已经使用使用 HeapCreate 并在那里分配该函数使用的缓冲区。
In my case the problem was a C++/CLI library in which there was a call to the NtQuerySystemInformation; for some kind of reason sometimes (and under mysterious circumstances), when it was called the CLR heap got corrupted and the application crashed.
I've resolved the problem using a "custom heap" created with HeapCreate and allocating there the buffers used by that function.
这可能是终结器中发生的异常。如果您正在执行 ~Class(){ Dispose(false); 的模式检查您将什么作为非托管资源进行处置。
只要尝试一下..抓住那里,你应该没问题。
我们发现了这个问题,因为我们遇到了这个神秘的故障,没有日志
我们采用了通常推荐的模式,即使用“void Dispose(bool dispose)”。
查看有关终结器的问题的答案,我们发现非托管资源的处置可能会引发异常的可能位置。
事实证明,我们在某个地方没有正确处置对象,因此终结器接管了非托管资源的处置,因此发生了异常。
在本例中,我们使用 Kafka Rest API 来清除 Kafka 中的客户端。似乎它确实在某个时候引发了异常,然后发生了这个问题。
This might be an exception occurring in the finalizer. If you are doing the Pattern of ~Class(){ Dispose(false); } check what are you disposing as an un-managed resource.
Just put a try..catch there and you should be fine.
We found the issue as we had this mysterious failure with no logs
We did the usual recommended pattern of using a "void Dispose(bool disposing)".
Looking at the answers on this question about the finalizer we found a possible place where the Disposal of the unmanaged resources could throw an exception.
It turns out somewhere we did not dispose the object properly thus the finalizer took over the diposal of unmanaged resources thus behold an exception occurred.
In this case was using the Kafka Rest API to clean up the client from Kafka. Seems that it did threw exception at some point then this issue occurred.
我不确定它对每个人都有帮助,但我可以通过
在路径
{Visual_Studio_root}\Common7\Ide
中运行 ...来解决这个问题,我在事件日志中遇到以下错误,VS 只是总是崩溃并重新启动:
I am not sure it may help everyone, but I could get around this by running
...in the path
{Visual_Studio_root}\Common7\Ide
I had the following errors in the event log and VS was just crashing and restarting all the time:
就我而言,问题是由于 web.config 中的重复绑定重定向造成的。更多信息此处。
我认为这是因为 NuGet 修改了绑定重定向,但例如它看起来像这样:
删除所有重复项解决了问题。
In my case the issue was due to duplicate binding redirects in my web.config. More info here.
I assume it was because of NuGet modifying the binding redirects, but for example it was looking like this:
Removing all the duplicates solved the problem.