C# 应用程序在 List.Enumerator 内崩溃

发布于 2024-11-29 22:30:10 字数 1085 浏览 0 评论 0原文

我在使用我公司编写的一款软件时遇到问题,它是一个作为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

给妤﹃绝世温柔 2024-12-06 22:30:11

如果异常发生在 Windows 服务的后台线程上,该服务将崩溃。看起来传入 InsertRangeIEnumerablenull

解决这个问题,问题就会消失,但是您仍然容易崩溃。我建议所有后台线程捕获并处理异常。例如,要启动一个安全的线程池线程,您可以执行以下操作:

ThreadPool.QueueUserWorkItem(o =>
    {
        try
        {
            //...
        }
        catch (Exception e)
        {
            Log.Error(e);
        }
    }

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 into InsertRange is null.

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:

ThreadPool.QueueUserWorkItem(o =>
    {
        try
        {
            //...
        }
        catch (Exception e)
        {
            Log.Error(e);
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文