C# 应用程序在 List.Enumerator 内崩溃
我在使用我公司编写的一款软件时遇到问题,它是一个作为 Windows 服务运行的实时服务器,使用 RabbitMQ 与 WebApplication/Silverlight 客户端进行交互。启动服务后 10 分钟到 2 周内,它会意外崩溃。应用程序事件查看器中记录了 2 个错误(我已将类和 exe 名称替换为 XXX):
来源:应用程序错误,EventId:1000,任务:(100)
故障应用程序 XXX.exe,版本 0.0.1.18195,时间戳 0x4e4a015e,故障模块 clr.dll,版本 4.0.30319.1,时间戳 0x4ba21eeb,异常代码0xc0000005,故障偏移量 0x000000000018063e,进程 ID 0x%9,应用程序启动时间 0x%10。
来源
:.NET 运行时,EventId:1023,任务:无
应用程序:XXX.exe 框架版本:v4.0.30319 描述: 由于 .NET 运行时中的内部错误,进程被终止 IP 000007FEF973063E (000007FEF95B0000),退出代码 80131506。
并且抛出以下异常。它似乎在迭代列表的底层数组时遇到问题,这怎么可能是空的超出了我的范围。
XXX`1[XXX];异常:System.NullReferenceException:对象 未设置对对象实例的引用。在 System.Collections.Generic.List`1.Enumerator.MoveNext() at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext() at System.Collections.Generic.List`1.InsertRange(Int32索引, IEnumerable`1集合)
我尝试将 ADPlus 附加到该服务,但是它减慢了速度,以至于无法使用。由于 Dr. Watson 不再可用,因此很难获取内存转储,任何人都可以推荐任何其他不会对性能产生太大影响的工具吗?
以前有人见过这样的事情吗?
I am having issues with a piece of software my company has written, it is a real-time server running as a windows service that uses RabbitMQ to interface with a WebApplication/Silverlight Client. It is crashing unexpectedly anywhere between 10 minutes and 2 weeks after starting the service. 2 errors are logged in the application event viewer (I have replaced the class and exe names with XXX):
Source: Application Error, EventId: 1000, Task: (100)
Faulting application XXX.exe, version 0.0.1.18195, time stamp
0x4e4a015e, faulting module clr.dll, version 4.0.30319.1, time stamp
0x4ba21eeb, exception code 0xc0000005, fault offset
0x000000000018063e, process id 0x%9, application start time 0x%10.
and
Source: .NET Runtime, EventId: 1023, Task: None
Application: XXX.exe Framework Version: v4.0.30319 Description: The
process was terminated due to an internal error in the .NET Runtime at
IP 000007FEF973063E (000007FEF95B0000) with exit code 80131506.
And the following exception is being thrown. It seems to be having issues iterating over the underlying array of a list, how this can be null is beyond me.
XXX`1[XXX]; Exception: System.NullReferenceException: Object
reference not set to an instance of an object. at
System.Collections.Generic.List`1.Enumerator.MoveNext() at
System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext() at
System.Collections.Generic.List`1.InsertRange(Int32 index,
IEnumerable`1 collection)
I have tried attaching ADPlus to the service however it slows it down so much it is unusable. As Dr. Watson is no longer available its difficult to get a memory dump, can anyone recommend any other tools that will not impact performance too much?
Has anyone seen anything like this before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果异常发生在 Windows 服务的后台线程上,该服务将崩溃。看起来传入
InsertRange
的IEnumerable
是null
。解决这个问题,问题就会消失,但是您仍然容易崩溃。我建议所有后台线程捕获并处理异常。例如,要启动一个安全的线程池线程,您可以执行以下操作:
If the exception is occurring on a background thread in a Windows service, the service will crash. It looks like the
IEnumerable<T>
being passed intoInsertRange
isnull
.Fix that and the problem should go away, however you are still vulnerable to crashes. I would recommend that all your background threads catch and handle exceptions. For example to start a safe threadpool thread you could do something like: