收藏异常异常 [英] Weird exception on collection

查看:540
本文介绍了收藏异常异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试添加/插入/删除集合(或任何更改集合的操作)时,我得到以下异常。
该集合被初始化,插入的项目不为零,并且与集合T的类型相同。

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?

运行时遇到致命错误。错误的地址是 0x60f41744 ,线程 0x231c 。错误代码是 0x80131623

此错误可能是CLR中的错误或用户代码的不安全或不可验证部分。此错误的常见来源包括COM-interop或PInvoke的用户编组错误,可能会损坏堆栈。

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.

更新:
集合是一个 ObservableCollection ,我设法知道它发生在收集的通知部分发生变化。

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.

这发生在使用 TaskScheduler.FromCurrentSynchronizationContext()选项的任务内的UI线程。

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

奇怪的是如果我删除这个( TaskScheduler.FromCurrentSynchronizationContext())选项的add / insert / remove操作,似乎都运行良好。

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

推荐答案


错误代码为0x80131623

The error code is 0x80131623

这是一个非常具体的错误代码COR_E_FAILFAST。只有一种方法来生成它,有人称之为Environment.FailFast()。

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

显然,挑战是找出所谓的代码。首先查看Windows应用程序事件日志中,应该有一个消息,它提供了调用的主要原因,无论字符串传递给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().


应用程序通过System.Environment.FailFast(字符串消息)请求进程终止。在System.Environment.FailFast(System.String)上的

System.Windows.WeakEventManager.DeliverEventToList(System.Object,System.EventArgs,ListenerList)中的


在System.Windows.WeakEventManager.DeliverEvent(System.Object,System.EventArgs)

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)

是的,该代码中有一个Assert() 。我只是发布我在参考源中可以看到的,我不知道你的代码,看看你做错了什么。除此之外,线程当然是触发此类问题的好方法,ObservableCollection完全是线程不安全的,必须被锁定保护。

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

这篇关于收藏异常异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆