首页 文章

在创建新选项卡后切换选项卡时抛出System.ArgumentException

提问于
浏览
0

我们发现在通过Windows Update安装.Net 4.5.1之后,会引入以下错误 . 我们当前的修复程序,不会持续很长时间,是卸载更新并将每个人的机器保持在.Net 4.0 .

我们有一个WPF屏幕,用于运行和查看报告 . 每个报告都是“ReportViewModel” . 视图模型的集合在“ReportManagerViewModel”中进行管理,该“ReportManagerViewModel”管理使用Caliburn.Micro.Conductor的选项卡集合 .

如果我们打开现有标签,则标签会完美加载 . 然后,我们启动一个新选项卡,运行一个报告,将焦点放在新选项卡上并填充其数据 . 此选项卡现在是选项卡集合的一部分 . 如果我们尝试切换回其中一个已打开的选项卡,则会发生以下情况:

第一次单击(第一次单击预先存在的选项卡)不执行任何操作 . 第二次单击使应用程序崩溃,并出现以下错误:

System.ArgumentException:已添加具有相同键的项 .

有趣的是,当切换活动选项卡时,会调用Conductor.ActivateItem() . 抛出错误时,甚至不调用此方法 .

使用Visual Studio 2010,Caliburn.Micro v.1.5.2,Telerik WPF控制2013年第3季度热修复1424 .

编辑:我们现在知道Telerik不是原因,因为我们从RadTabItem切换到TabItem并且我们没有使用Caliburn.Micro.Conductor .

EXCEPTION:已添加具有相同键的项目 . SOURCE:mscorlib STACK TRACE:位于System.Collections.Generic.Dictionary2.Insert(TKey键,TValue值,布尔加法)的System.ThrowHelper.ThrowArgumentException(ExceptionResource资源),位于System.Collections.Generic.Dictionary2..ctor(IDictionary2字典) System.Windows.Controls上System.Windows.Controls.Primitives.Selector.SelectionChanger.ApplyCanSelectMultiple()的System.Windows.Controls.Primitives.Selector.InternalSelectedItemsStorage..ctor(InternalSelectedItemsStorage集合,IEqualityComparer`1 equalityComparer)中的IEqualityComparer1 comparer) System.Windows.Controls.Primitives.Selector.NotifyIsSelectedChanged(FrameworkElement容器,布尔选中)的System.Windows.Controls.Primitives.Selector.SetSelectedHelper(Object item,FrameworkElement UI,Boolean selected)中的.Primitives.Selector.SelectionChanger.End() ,RoutedEventArgs e)位于System.Windows.RoutedEventHandlerInfo.Inv的System.Windows.Controls.Primitives.Selector.OnSelected(Object sender,RoutedEventArgs e)在System.Windows.Uindlement.RaiseEvent的System.Windows.UIElement.RaiseEventImpl(DependencyObject sender,RoutedEventArgs args)的System.Windows.EventRoute.InvokeHandlersImpl(Object source,RoutedEventArgs args,Boolean reRaised)中的okeHandler(Object target,RoutedEventArgs routedEventArgs)(在System.Windows的System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)的System.Windows.Controls.TabItem.OnIsSelectedChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)中的System.Windows.Controls.TabItem.OnSelected(RoutedEventArgs e)处的RoutedEventArgs e)在System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs参数)在System.Windows.DependencyObject.UpdateEffectiveValue(entryIndex entryIndex,的DependencyProperty DP,PropertyMetadata元数据,EffectiveValueEntry oldEntry,EffectiveValueEntry&newEntry,布尔coerceWithDeferredReference,Boolea .FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs E) System.Windows.DependencyObject.SetCurrentValueInternal(DependencyProperty dp,Object value)中的System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp,Object value,PropertyMetadata metadata,Boolean coerceWithDeferredReference,Boolean coerceWithCurrentValue,OperationType operationType,Boolean isInternal)中的coerceWithCurrentValue,OperationType operationType)处于System.Windows.Uindlement.OnPreviewGotKeyboardFocusThunk(对象发送者,KeyboardFocusChangedEventArgs e)的System.Windows.Controls.TabItem.OnPreviewGotKeyboardFocus(KeyboardFocusChangedEventArgs e)处的System.Windows.Input.KeyboardFocusChangedEventArgs.InvokeEventHandler(Delegate genericHandler,Object genericTarget) . 位于System.Windows.EventRoute.InvokeHandlersImpl的System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target,RoutedEventArgs routedEventArgs)中的Windows.RoutedEventArgs.InvokeHandler(委托处理程序,Object目标)(对象源,RoutedEventArgs args,BooleanreRaised)在System.Windows.Uindlement.RaiseEventImpl(DependencyObject sender,RoutedEventArgs args)的System.Windows.Uindlement.RaiseTrustedEvent(RoutedEventArgs args)处于System.Windows.Uindlement.RaiseEvent(RoutedEventArgs args,布尔值为受信任),位于System.Windows.Input System.Windows上System.Windows.Input.KeyboardDevice.TryChangeFocus(DependencyObject newFocus,IKeyboardInputProvider keyboardInputProvider,Boolean askOld,Boolean askNew,Boolean forceToNullIfFailed)的System.Windows.Input.InputManager.ProcessInput(InputEventArgs输入)中的.InputManager.ProcessStagingArea() .Input.KeyboardDevice.Focus(DependencyObject focus,Boolean askOld,Boolean askNew,Boolean forceToNullIfFailed),位于System.Windows.Controls的System.Windows.UIElement.Focus()的System.Windows.Input.KeyboardDevice.Focus(IInputElement元素) . System.Windows.UIElement.OnMouseLeftButtonDownThunk(对象发送者,鼠标)中的System.Windows.Controls.TabItem.OnMouseLeftButtonDown(MouseButtonEventArgs e)中的TabItem.SetFocus() ButtonEventArgs e)在System.Windows.RindtedEventArgs.InvokeHandler(委托处理程序,Object目标)的System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler,Object genericTarget)处于System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target,RoutedEventArgs routedEventArgs)在System.Windows.Uindlement.OnMouseDownThunk的System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender,RoutedEventArgs args,RoutedEvent newEvent)上的System.Windows.EventRoute.InvokeHandlersImpl(Object source,RoutedEventArgs args,Boolean reRaised)(Object sender,MouseButtonEventArgs e) )System.Windows.RindtedEventArgs.InvokeHandler(委托处理程序,对象目标)的System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler,Object genericTarget)at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target,RoutedEventArgs routedEventArgs)at System .Windows.EventRoute.InvokeHandlersImpl(Object source,RoutedEventArgs args,Boolean reRaised)在System.Windows.Uindlement.RaiseEventImpl(DependencyObject sender,RoutedEventArgs args)的System.Windows.Uindlement.RaiseTrustedEvent(RoutedEventArgs args)处于System.Windows.Uindlement.RaiseEvent(RoutedEventArgs args,布尔值为受信任),位于System.Windows.Input System.Windows.Inputop.HwndMouseInputProvider.ReportInput(IntPtr hwnd,InputMode mode)中System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)的System.Windows.Input.InputManager.ProcessInput(InputEventArgs输入)中的.InputManager.ProcessStagingArea() System.Windows.Interop.HwndSource上的System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd,WindowMessage msg,IntPtr wParam,IntPtr lParam,Boolean&handling)中的,Int32 timestamp,RawMouseActions操作,Int32 x,Int32 y,Int32 wheel) MS处于MS.Win32.HwndWrapper.WndProc(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,Boolean&handling)的.InputFilterMessage(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,Boolean&handling) . System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调,Object args,Int32 numArgs)中的Win32.HwndSubclass.DispatcherCallbackOperation(Object o)位于MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source,Delegate方法,Object args,Int32)在MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr)的System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority,TimeSpan timeout,Delegate方法,Object args,Int32 numArgs)中的numArgs,Delegate catchHandler) lParam)at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&msg)at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID,Int32 reason,Int32 pvLoopData)at System System.Windows.Forms.Application.ThreadContext.RunMessageLoop中的.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason,ApplicationContext context)(Int32原因, ApplicationContext上下文)在System.Windows.Forms.Application.Run(Form mainForm)位于[AppName] .Windows.Program.Main()的M:\ Projects [AppName] \ Windows \ Program.cs:第129行

2 回答

  • 0

    http://support.microsoft.com/kb/2909048

    TabViewModel的“GetHashCode()”和“Equals()”方法是问题的根源 . 这些将需要重写或删除 .

  • 1

    只是对已接受答案的详细说明 . 当我更改绑定值并重新选择项目时,我有一个与ListBox相同的ArgumentException(加号DataTemplate交换选择) . 以下内容适用于我(当然,您必须确保索引值在列表中是唯一的):

    public override bool Equals(object obj)
            {
                if (obj is ExtendedButton2Content)
                {
                    ExtendedButton2Content temp = (ExtendedButton2Content)obj;
                    return temp.Index == this.Index;
                }
                else
                {
                    return false;
                }
            }
    
            public override int GetHashCode()
            {
                return Index;
            }
    

相关问题