WPF绑定异常

发布于 2025-02-13 02:09:51 字数 1917 浏览 0 评论 0原文

我们使用PRISM 6.0的WPF应用程序,该应用程序具有不同的屏幕显示收藏集。这些视图中的许多观点都加载在启动中,并显示为必要。

从零星的角度来看,我们在创业公司中得到了一个例外。异常呼叫堆栈没有提供任何有用的信息(除了它是跨线程收集访问问题外),我们发现很难找到根本原因。例外是如下,

at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at System.Collections.Generic.List`1.get_Item(Int32 index)
at System.Collections.ObjectModel.Collection`1.get_Item(Int32 index)
at System.Collections.ObjectModel.ReadOnlyCollection`1.System.Collections.ICollection.CopyTo(Array array, Int32 index)
at System.Collections.ArrayList.InsertRange(Int32 index, ICollection c)
at System.Collections.ArrayList.AddRange(ICollection c)
at System.Collections.ArrayList..ctor(ICollection c)
at System.Windows.Data.ListCollectionView.<RefreshOverride>b__1_0()
at MS.Internal.Data.SynchronizationInfo.AccessCollection(IEnumerable collection, Action accessMethod, Boolean writeAccess)
at System.Windows.Data.BindingOperations.AccessCollection(IEnumerable collection, Action accessMethod, Boolean writeAccess)
at System.Windows.Data.ListCollectionView.RefreshOverride()
at System.Windows.Data.CollectionView.RefreshInternal()
at System.Windows.Data.CollectionView.RefreshOrDefer()
at System.Windows.Data.ListCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
at System.Windows.Data.CollectionView.ProcessChangeLog(ArrayList changeLog, Boolean processAll)
at System.Windows.Data.CollectionView.ProcessInvoke(Object arg)
at MS.Internal.Data.DataBindOperation.Invoke()
at MS.Internal.Data.DataBindEngine.ProcessCrossThreadRequests()
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

有什么方法是什么方法(至少是收集元素的类型)引起了此问题或找到根本原因的任何方法?

欢迎任何想法!

谢谢

We have a WPF application using Prism 6.0 which have different screens that show collections. Many of these views are loaded in the startup and shown as necessary.

Sporadically, we are getting an exception in the startup. The exception call-stack does not give any useful information (except that it is a cross thread collection access issue) and we are finding it difficult to find the root cause. The exception is as below

at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at System.Collections.Generic.List`1.get_Item(Int32 index)
at System.Collections.ObjectModel.Collection`1.get_Item(Int32 index)
at System.Collections.ObjectModel.ReadOnlyCollection`1.System.Collections.ICollection.CopyTo(Array array, Int32 index)
at System.Collections.ArrayList.InsertRange(Int32 index, ICollection c)
at System.Collections.ArrayList.AddRange(ICollection c)
at System.Collections.ArrayList..ctor(ICollection c)
at System.Windows.Data.ListCollectionView.<RefreshOverride>b__1_0()
at MS.Internal.Data.SynchronizationInfo.AccessCollection(IEnumerable collection, Action accessMethod, Boolean writeAccess)
at System.Windows.Data.BindingOperations.AccessCollection(IEnumerable collection, Action accessMethod, Boolean writeAccess)
at System.Windows.Data.ListCollectionView.RefreshOverride()
at System.Windows.Data.CollectionView.RefreshInternal()
at System.Windows.Data.CollectionView.RefreshOrDefer()
at System.Windows.Data.ListCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
at System.Windows.Data.CollectionView.ProcessChangeLog(ArrayList changeLog, Boolean processAll)
at System.Windows.Data.CollectionView.ProcessInvoke(Object arg)
at MS.Internal.Data.DataBindOperation.Invoke()
at MS.Internal.Data.DataBindEngine.ProcessCrossThreadRequests()
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Is there any way to which collection (at least the type of collection elements) is causing this issue or any way to find the root cause?

Any ideas are welcome!

thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

看海 2025-02-20 02:09:52

当用于访问集合的索引小于零或等于或大于集合的count时,通常会抛出此例外。

跨线程异常通常为notsupportedException

您必须确保索引在范围内。

要查找确切位置,您必须转到“调试菜单”,并使调试器能够打破所有例外,然后在调试模式下运行您的应用程序:

  1. ctrl+alt+alt+e ,并勾选“通用语言运行时异常“复选框
  2. 以调试模式运行,以使程序停止在原始线(如果适当的例外处理)中,

则从您的异常消息中,看起来堆栈跟踪是从发行版构建中生成的。

在这种情况下,请确保您也发布PDB文件(调试符号)。这将允许异常堆栈跟踪包括行号。

另一个选择是查看您的所有基于索引的收集访问(读取),并防止索引超出范围(应该是生产代码的标准)。您也可以利用这种场合来进行基于索引的写入访问。您可以使用搜索工具在解决方案中找到索引器。

即使您包括PDB文件或使用调试模式来识别原始线,也应该考虑在搜索工具的帮助下查看其他基于脆弱索引的收集访问的代码库。也许在您的编码指南中添加规则,以迫使开发人员在通过索引访问汇编之前检查集合界限。

This exception is usually thrown when the index used to access the collection is less than zero or equal to or greater than the collection's Count.

A cross-thread exception would usually be of type NotSupportedException.

You must ensure that the index is within the range.

To find the exact location you must go to the Debug menu and enable the debugger to break on all exceptions and then run you application in debug mode:

  1. Press Ctrl+Alt+E and tick the "Common Language Runtime Exceptions" check box
  2. Run in debug mode to make the program halt at the line of origin (in case of proper exception handling)

From your exception message it looks like the stack trace is generated from a release build.
In this case make sure you publish the PDB files too (debug symbols). This will allow the exception stack trace to include line numbers.

Another option is to review all your index based collection access (read) and guard against an index out of range (it should be standard in production code). You could use the occasion to do this for index based write access too. You can use the search tool to locate indexers in your solution.

Even if you include PDB files or use the debug mode to identify the line of origin, you should consider to review your code base for other brittle index based collection access with the help of the search tool. And maybe add a rule to your coding guide to force developers to check the collection bounds before accessing it by index.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文