开发者

C# Application crashing inside List.Enumerator

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, f开发者_JAVA技巧aulting 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?


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);
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜