7
Vote

Datagrid binding to ObjectDataProvider works while debugging but not when running

description

I am experiencing a problem where databinding works just fine while debugging. But when the application is run, it crashes reporting a problem with AutomationPeers? I would debug it myself but I am unable to get it to fall over at all when debugging and I am therefore unable to see where it is going wrong. I have attached a small test project that I used to recreate the problem as I was experiencing it in the project proper. Some help would be HUGELY appreciated. I am new to WPF so it is entirely possible that I am doing something silly.
 
Many thanks in anticipation....

file attachments

comments

kingcanfly wrote Oct 12, 2010 at 7:50 AM

I am sure this might help. It is the details of the exception. This is as far as I could get in debugging this problem. The problem seems to be really eratic. I was able to get it working some of the time in the test app but I had to empty the obj and bin folders first...

Anyway, the stack trace follows:

System.InvalidOperationException was unhandled
Message=Recursive call to Automation Peer API is not valid.
Source=PresentationCore
StackTrace:
   at System.Windows.Automation.Peers.AutomationPeer.GetChildren()
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.ValidateConnected(AutomationPeer connectedPeer)
   at MS.Internal.Automation.ElementProxy.StaticWrap(AutomationPeer peer, AutomationPeer referencePeer)
   at System.Windows.Automation.Peers.AutomationPeer.UpdateChildrenInternal(Int32 invalidateLimit)
   at System.Windows.Automation.Peers.AutomationPeer.UpdateChildren()
   at Microsoft.Windows.Automation.Peers.DataGridItemAutomationPeer.GetChildrenCore() in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\DataGrid\Microsoft\Windows\Automation\Peers\DataGridItemAutomationPeer.cs:line 86
   at System.Windows.Automation.Peers.AutomationPeer.EnsureChildren()
   at System.Windows.Automation.Peers.AutomationPeer.GetChildren()
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
   at System.Windows.Automation.Peers.AutomationPeer.ValidateConnected(AutomationPeer connectedPeer)
   at MS.Internal.Automation.ElementProxy.StaticWrap(AutomationPeer peer, AutomationPeer referencePeer)
   at System.Windows.Automation.Peers.AutomationPeer.ProviderFromPeer(AutomationPeer peer)
   at System.Windows.Automation.Peers.AutomationPeer.RaiseAutomationEvent(AutomationEvents eventId)
   at System.Windows.Automation.Peers.SelectorAutomationPeer.RaiseSelectionEvents(SelectionChangedEventArgs e)
   at System.Windows.Controls.ComboBox.OnSelectionChanged(SelectionChangedEventArgs e)
   at System.Windows.Controls.Primitives.Selector.InvokeSelectionChanged(List`1 unselectedItems, List`1 selectedItems)
   at System.Windows.Controls.Primitives.Selector.SelectionChanger.End()
   at System.Windows.Controls.Primitives.Selector.SelectionChanger.SelectJustThisItem(Object item, Boolean assumeInItemsCollection)
   at System.Windows.Controls.Primitives.Selector.SelectItemWithValue(Object value)
   at System.Windows.Controls.Primitives.Selector.CoerceSelectedValue(DependencyObject d, Object value)
   at System.Windows.DependencyObject.ProcessCoerceValue(DependencyProperty dp, PropertyMetadata metadata, EntryIndex& entryIndex, Int32& targetIndex, EffectiveValueEntry& newEntry, EffectiveValueEntry& oldEntry, Object& oldValue, Object baseValue, Object controlValue, CoerceValueCallback coerceValueCallback, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, Boolean skipBaseValueChecks)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp)
   at System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange)
   at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
   at System.Windows.Data.BindingExpression.Activate(Object item)
   at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
   at System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean lastChance)
   at MS.Internal.Data.DataBindEngine.Task.Run(Boolean lastChance)
   at MS.Internal.Data.DataBindEngine.Run(Object arg)
   at MS.Internal.Data.DataBindEngine.OnLayoutUpdated(Object sender, EventArgs e)
   at System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
   at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at ITISDeskTop.App.Main() in C:\Projects\ITIS_NRA\Source\Desktop\ITISDesktop WPF\trunk\ITISDeskTop WPF\ITISDeskTop\obj\x86\Debug\App.g.cs:line 50
InnerException:

kingcanfly wrote Oct 13, 2010 at 8:52 AM

Done some more testing....I managed to get this working using the following code rather than the built in DataGridComboBoxColumn :
        <dg:DataGridTemplateColumn Header="Designer" Width="250">
            <dg:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding DESIGNER_STR}" VerticalAlignment="Center" Margin="2"/>
                </DataTemplate>
            </dg:DataGridTemplateColumn.CellTemplate>
            <dg:DataGridTemplateColumn.CellEditingTemplate>
                <DataTemplate>
                    <ComboBox Height="22"  
                              ItemsSource="{Binding Lookups.WLU_ALL_INV_DESIGNENGINEERS}"
                              DisplayMemberPath="DISPLAYSTRING"
                              SelectedValuePath="VALUE"
                              SelectedValue="{Binding DESIGNER}"/>
                </DataTemplate>
            </dg:DataGridTemplateColumn.CellEditingTemplate>
        </dg:DataGridTemplateColumn>
The problem happens on either Value binding or Item binding. The value in my database is an int, the lookup items contain strings for display and integers for values. So still not sure why this is happening.

wrote Nov 23, 2010 at 1:18 PM

wrote Mar 15, 2011 at 9:23 PM

wrote Apr 2, 2012 at 5:26 AM

wrote Jun 1, 2012 at 9:05 PM

wrote Feb 22, 2013 at 1:40 AM

wrote Nov 6, 2014 at 8:32 AM

jenik15 wrote Nov 6, 2014 at 8:37 AM

Same problem.
Only on release PC problem can be reproduced.
                    <controls:ScrollableDataGrid ColumnFontSize="20" Style="{DynamicResource PosDataGridStyle}" 
                    ItemsSource="{wpflib:Binding StockInfo}" 
                    Margin="9,0,5,5"
                    RowHeaderWidth="0"
                    CanUserAddRows="False"
                    CanUserDeleteRows="False"
                    CanUserResizeRows="False"
                    CanUserReorderColumns="False"
                    RowDetailsVisibilityMode="Collapsed"
                    AutoGenerateColumns="False"
                    Grid.ColumnSpan="2"
                    x:Name="stockInfo"
                    CanUserResizeColumns="False"
                    VerticalAlignment="Stretch"
                    SelectionMode="Single" MinColumnWidth="36" HeadersVisibility="Column" VerticalScrollBarVisibility="Auto">
                    <controls:ScrollableDataGrid.Columns>
                        <custom:DataGridTemplateColumn Width="Auto" Header="{lm:Translate StockViewHeading_StoreName}">
                            <custom:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock
                                        FontSize="16"
                                        Margin="4,0,4,0"
                                        VerticalAlignment="Center"
                                        HorizontalAlignment="Right"
                                        Text="{wpflib:Binding StoreNumber}" />
                                </DataTemplate>
                            </custom:DataGridTemplateColumn.CellTemplate>
                        </custom:DataGridTemplateColumn>
                        <custom:DataGridTemplateColumn Width="*" Header="">
                            <custom:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock FontSize="16" Margin="4,0,4,0" VerticalAlignment="Center" HorizontalAlignment="Left" Text="{wpflib:Binding StoreName}"/>
                                </DataTemplate>
                            </custom:DataGridTemplateColumn.CellTemplate>
                        </custom:DataGridTemplateColumn>
                        <custom:DataGridTemplateColumn Width="Auto" Header="{lm:Translate StockViewHeading_QuantityInStock}">
                            <custom:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock FontSize="16" Margin="4,0,4,0" VerticalAlignment="Center" HorizontalAlignment="Left" Text="{wpflib:Binding QuantityInStock}"/>
                                </DataTemplate>
                            </custom:DataGridTemplateColumn.CellTemplate>
                        </custom:DataGridTemplateColumn>
                        <custom:DataGridTemplateColumn Width="Auto" Header="{lm:Translate StockViewHeading_QuantityReserved}">
                            <custom:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock FontSize="16" Margin="4,0,4,0" VerticalAlignment="Center" HorizontalAlignment="Left" Text="{wpflib:Binding QuantityReserved}"/>
                                </DataTemplate>
                            </custom:DataGridTemplateColumn.CellTemplate>
                        </custom:DataGridTemplateColumn>
                        <custom:DataGridTemplateColumn Width="Auto" Header="{lm:Translate StockViewHeading_QuantityOnOrder}">
                            <custom:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock FontSize="16" Margin="4,0,4,0" VerticalAlignment="Center" HorizontalAlignment="Left" Text="{wpflib:Binding QuantityOnOrder}"/>
                                </DataTemplate>
                            </custom:DataGridTemplateColumn.CellTemplate>
                        </custom:DataGridTemplateColumn>
                        <custom:DataGridTemplateColumn Width="Auto" Header="{lm:Translate StockViewHeading_QuantityAvailable}">
                            <custom:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock FontSize="16" Margin="4,0,4,0" VerticalAlignment="Center" HorizontalAlignment="Left" Text="{wpflib:Binding QuantityAvailable}"/>
                                </DataTemplate>
                            </custom:DataGridTemplateColumn.CellTemplate>
                        </custom:DataGridTemplateColumn>
                        <custom:DataGridTemplateColumn Width="Auto" Header="{lm:Translate StockViewHeading_Location}">
                            <custom:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock FontSize="16" Margin="4,0,4,0" VerticalAlignment="Center" HorizontalAlignment="Right" Text="{wpflib:Binding Location}"/>
                                </DataTemplate>
                            </custom:DataGridTemplateColumn.CellTemplate>
                        </custom:DataGridTemplateColumn>
                    </controls:ScrollableDataGrid.Columns>
                </controls:ScrollableDataGrid>


Exception occured in application (AppWide)',
System.InvalidOperationException: 'Rekursivt anrop till Automation Peer API är inte giltigt.'
vid System.Windows.Automation.Peers.AutomationPeer.GetChildren()
vid System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
vid System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
vid System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
vid System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
vid System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
vid System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
vid System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
vid System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
vid System.Windows.Automation.Peers.AutomationPeer.ValidateConnected(AutomationPeer connectedPeer)
vid MS.Internal.Automation.ElementProxy.StaticWrap(AutomationPeer peer, AutomationPeer referencePeer)
vid System.Windows.Automation.Peers.AutomationPeer.UpdateChildren()
vid System.Windows.Automation.Peers.AutomationPeer.ResetChildrenCache()
vid Microsoft.Windows.Automation.Peers.DataGridCellItemAutomationPeer.GetChildrenCore()
vid System.Windows.Automation.Peers.AutomationPeer.EnsureChildren()
vid System.Windows.Automation.Peers.AutomationPeer.GetChildren()
vid System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
vid System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
vid System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
vid System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
vid System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
vid System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
vid System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
vid System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
vid System.Windows.Automation.Peers.AutomationPeer.ValidateConnected(AutomationPeer connectedPeer)
vid System.Windows.Automation.Peers.AutomationPeer.AutomationPeerFromInputElement(IInputElement focusedElement)
vid System.Windows.Automation.Peers.AutomationPeer.RaiseFocusChangedEventHelper(IInputElement newFocus)
vid System.Windows.Input.KeyboardDevice.ChangeFocus(DependencyObject focus, Int32 timestamp)
vid System.Windows.Input.KeyboardDevice.TryChangeFocus(DependencyObject newFocus, IKeyboardInputProvider keyboardInputProvider, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed)
vid System.Windows.Input.KeyboardDevice.Focus(DependencyObject focus, Boolean askOld, Boolean askNew)
vid System.Windows.Input.KeyboardDevice.Focus(IInputElement element)
vid System.Windows.UIElement.Focus()
vid System.Windows.FrameworkElement.OnPreviewGotKeyboardFocus(Object sender, KeyboardFocusChangedEventArgs e)
vid System.Windows.Input.KeyboardFocusChangedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
vid System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
vid System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
vid System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
vid System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
vid System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
vid System.Windows.Input.InputManager.ProcessStagingArea()
vid System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
vid System.Windows.Input.KeyboardDevice.TryChangeFocus(DependencyObject newFocus, IKeyboardInputProvider keyboardInputProvider, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed)
vid System.Windows.Input.KeyboardDevice.Focus(DependencyObject focus, Boolean askOld, Boolean askNew)
vid System.Windows.Input.KeyboardDevice.Focus(IInputElement element)
vid System.Windows.Interop.HwndKeyboardInputProvider.FilterMessage(IntPtr hwnd, Int32 message, IntPtr wParam, IntPtr lParam, Boolean& handled)
vid System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
vid MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
vid MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
vid System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
vid System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

wrote Mar 3, 2015 at 3:26 PM