Weird exception on collection

4

I get the below exception when I try to add/insert/remove to a collection (or any operation that changes the collection). The collection is initialized and the item inserted is not null and of the same type as the collection T.

Can any one give me a clue as to why this happens?

The runtime has encountered a fatal error. The address of the error was at 0x60f41744, on thread 0x231c. The error code is 0x80131623.
This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.

Update: The collection is an ObservableCollection, and I managed to get down to know that it happens on the notify part of the collection changed.

This happens on the UI thread inside a task with the TaskScheduler.FromCurrentSynchronizationContext() option.

The weird thing is if I remove this (TaskScheduler.FromCurrentSynchronizationContext()) option the add/insert/remove action, all seems to work good.

wpf
exception
observablecollection
asked on Stack Overflow Jan 6, 2013 by shahar eldad • edited Jan 6, 2013 by Dave Clemmer

2 Answers

6

The error code is 0x80131623

That's a very specific error code, COR_E_FAILFAST. Only one way to generate it, somebody called Environment.FailFast().

Clearly the challenge is to find out what code called that. First look in the Windows Application event log, there ought to be a message about it that gives the primary reason for the call, whatever string was passed to FailFast().


The application requested process termination through System.Environment.FailFast(string message).
at System.Environment.FailFast(System.String)
at System.Windows.WeakEventManager.DeliverEventToList(System.Object, System.EventArgs, ListenerList)
at System.Windows.WeakEventManager.DeliverEvent(System.Object, System.EventArgs)

Yes, there's an Assert() in that code. I'll just post what I can see in the Reference Source, I don't know enough about your code to see what you did wrong. Other than that threading is certainly a good way to get this kind of problem triggered, ObservableCollection is entirely thread-unsafe and must be protected by a lock.

   // if the event isn't handled, something is seriously wrong.  This
   // means a listener registered to receive the event, but refused to
   // handle it when it was delivered.  Such a listener is coded incorrectly.
   if (!handled)
   {
       Invariant.Assert(handled,
                   SR.Get(SRID.ListenerDidNotHandleEvent),
                   SR.Get(SRID.ListenerDidNotHandleEventDetail, iwel.GetType(), managerType));
   }
answered on Stack Overflow Jan 6, 2013 by Hans Passant • edited Jan 6, 2013 by Hans Passant
-2

Bad memory, corrupt runtime.

THis is a fatal error like that - and thus it is NOT a .NET level mistake, it points toward some memory corruption for whatever reason, as it says. Could be bad memory, bad power supply, or a program error in a non-managed part that corrupted memory. OR an error in the runtime (JIT level, i.e. the part that deals with the assembler level, or the WPF/native area), but I somehow doubt that.

Btw., it is not too smart to post an error description without - ah - the TYPE of the error.

answered on Stack Overflow Jan 6, 2013 by TomTom

User contributions licensed under CC BY-SA 3.0