Home Forums WPF controls Xceed DataGrid for WPF DataGrid control: ContextSwitchDeadlock on Entity Framework’s deferred loading

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #31512 |

    Hi all,

    We use Xceed.Wpf.DataGrid control ver.3.1.9069.14010 with Entity Framework/SQL Server CE data binding in WPF application.
    Entity Framework provides deferred loading for related entity objects. This means the data is retrieved from DB on-demand.
    When the control gets static/loaded data everything works ok, but the application hangs when the control attempts to retrieve data from DB (EF’s RelatedEnd.Load method is called in such cases).

    The problem does not occur when the same data is retrieved without using the control.
    The only workaround I found that makes the control work is to forcibly process the message queue before calling RelatedEnd.Load method. Actually there is no legal way to do such things in WPF like DoEvents in Windows Forms, so the trick I used cannot be an acceptable workaround.

    So my assumption is either the control somehow blocks message pumping or we incorrectly use some control’s artefacts that relay on messaging mechanism.

    Does anyone know a correct solution?
    Any ideas or help would be greatly appreciated.

    Thanks,
    Anatoly

    Imported from legacy forums. Posted by Anatoly (had 4898 views)

    Xceed Support
    Member
    Post count: 5658

    Are you using the DataGridVirtualizingCollectionView? Would it be possible for you to provide more information in regards to your setup? Our initial tests here did not reveal any such issues with the datagrid and Entity framework.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 2904 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for your reply.
    We don’t use DataGridVirtualizingCollectionView, we use DataGridCollectionView and I did not see any asynchronous behaviour in regard to data binding – all calls to EF are made from the main thread. That’s exaclty what we need.

    So, we use DataGridCollectionView.
    DataGridCollectionViewSource.Source value is set to custom collection of data objects (the collection implements ICollection(T) interface).
    Data object is a wrapper around EF’s entity object.
    Entity can contain scalar values and navigation properties which allows an entity to access either an entity reference or entity collection.

    Scalar values
    Data object getters of scalar values just invoke corresponding getters of entity object. In this case entity members contain already loaded data and everything works correctly.

    Relationships
    Data object getters of related objects first explicitly load the related object(s) if they are not yet loaded:
    For entity collection (represents “many” end of a relationship) EntityCollection<TEntity>.Load method is called.
    For entity reference (represents “one” end of a relationship) EntityReference<TEntity>.Load method is called.

    As I wrote in my previous post, sometimes application hangs when one of such Load operations is performed.
    Below is the call stack.

    [Managed to Native Transition]              
    WindowsBase.dll!MS.Win32.UnsafeNativeMethods.WaitForMultipleObjectsEx(int nCount, System.IntPtr[] pHandles, bool bWaitAll, int dwMilliseconds, bool bAlertable) + 0x26 bytes      
    WindowsBase.dll!System.Windows.Threading.DispatcherSynchronizationContext.Wait(System.IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout) + 0x41 bytes           
     mscorlib.dll!System.Threading.SynchronizationContext.InvokeWaitMethodHelper(System.Threading.SynchronizationContext syncContext, System.IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout) + 0x1a bytes             
    [Native to Managed Transition]              
    [Managed to Native Transition]              
    System.Data.SqlServerCe.dll!System.Data.SqlServerCe.SqlCeConnection.ObjectLifeTimeTracker.Close(bool isDisposing) + 0x3f1 bytes          
    System.Data.SqlServerCe.dll!System.Data.SqlServerCe.SqlCeConnection.Close(bool silent) + 0x54 bytes        
    System.Data.SqlServerCe.dll!System.Data.SqlServerCe.SqlCeConnection.Close() + 0xf bytes 
    System.Data.Entity.dll!System.Data.EntityClient.EntityConnection.StoreCloseHelper() + 0x3e bytes   
    System.Data.Entity.dll!System.Data.EntityClient.EntityConnection.CloseHelper() + 0x1a bytes              
    System.Data.Entity.dll!System.Data.EntityClient.EntityConnection.Close() + 0x10 bytes            
    System.Data.Entity.dll!System.Data.Objects.ObjectContext.ReleaseConnection() + 0x36 bytes            
     System.Data.Entity.dll!System.Data.Common.Internal.Materialization.Shaper<ArcLogistics.Data.DataModel.FuelTypes>.Finally() + 0x2e bytes     
     System.Data.Entity.dll!System.Data.Common.Internal.Materialization.Shaper<System.__Canon>.SimpleEnumerator.Dispose() + 0x16 bytes     
     System.Data.Entity.dll!System.Data.Common.Internal.Materialization.Shaper<System.__Canon>.SimpleEnumerator.MoveNext() + 0x56 bytes     
     mscorlib.dll!System.Collections.Generic.List<ArcLogistics.Data.DataModel.FuelTypes>.List(System.Collections.Generic.IEnumerable<ArcLogistics.Data.DataModel.FuelTypes> collection) + 0x17a bytes            
     System.Data.Entity.dll!System.Data.Objects.DataClasses.EntityReference<ArcLogistics.Data.DataModel.FuelTypes>.Load(System.Data.Objects.MergeOption mergeOption = AppendOnly) + 0xc7 bytes        
    System.Data.Entity.dll!System.Data.Objects.DataClasses.RelatedEnd.Load() + 0x21 bytes        >
    ArcLogistics.dll!ArcLogistics.Data.EntityRefWrapper<ArcLogistics.DomainObjects.FuelType,ArcLogistics.Data.DataModel.FuelTypes>._Init() Line 65 + 0xd bytes         C#
     ArcLogistics.dll!ArcLogistics.Data.EntityRefWrapper<ArcLogistics.DomainObjects.FuelType,ArcLogistics.Data.DataModel.FuelTypes>.Value.get() Line 41 + 0x8 bytes         C#
    ArcLogistics.dll!ArcLogistics.DomainObjects.Vehicle.FuelType.get() Line 93 + 0x16 bytes        C#
    [Native to Managed Transition]              
    [Managed to Native Transition]              
    System.dll!System.ComponentModel.ReflectPropertyDescriptor.GetValue(object component = {ArcLogistics.DomainObjects.Vehicle}) + 0x65 bytes           
    Xceed.Wpf.DataGrid.dll!Xceed.Wpf.DataGrid.DataGridItemProperty.GetValue(object component = {ArcLogistics.DomainObjects.Vehicle}) + 0x63 bytes           
     Xceed.Wpf.DataGrid.dll!Xceed.Wpf.DataGrid.DataGridItemProperty.PropertyDescriptorFromItemProperty.GetValue(object component = {ArcLogistics.DomainObjects.Vehicle}) + 0x42 bytes              
    PresentationFramework.dll!MS.Internal.Data.ValueTable.GetValue(object item, System.ComponentModel.PropertyDescriptor pd, bool indexerIsNext) + 0x2d bytes 
    PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.GetValue(object item = {ArcLogistics.DomainObjects.Vehicle}, int level = 0) + 0x16f bytes               
    PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.RawValue(int k = 0) + 0xda bytes               
    PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.RawValue() + 0x12 bytes
    PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.RawValue() + 0x11 bytes       
    PresentationFramework.dll!System.Windows.Data.BindingExpression.TransferValue(object newValue, bool isASubPropertyChange = false) + 0x9a bytes    
    PresentationFramework.dll!System.Windows.Data.BindingExpression.Activate(object item) + 0xe7 bytes     
     PresentationFramework.dll!System.Windows.Data.BindingExpression.AttachToContext(System.Windows.Data.BindingExpression.AttachAttempt attempt) + 0x1de bytes              
     PresentationFramework.dll!System.Windows.Data.BindingExpression.AttachOverride(System.Windows.DependencyObject target = {Xceed.Wpf.DataGrid.DataCell}, System.Windows.DependencyProperty dp = {System.Windows.DependencyProperty}) + 0x5f bytes             
     PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.Attach(System.Windows.DependencyObject target, System.Windows.DependencyProperty dp) + 0x30 bytes          
     PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.OnAttach(System.Windows.DependencyObject d, System.Windows.DependencyProperty dp) + 0x1f bytes     
    WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty dp = {System.Windows.DependencyProperty}, object value, System.Windows.PropertyMetadata metadata = {System.Windows.FrameworkPropertyMetadata}, bool coerceWithDeferredReference = false, System.Windows.OperationType operationType = Unknown, bool isInternal) + 0x295 bytes  
    WindowsBase.dll!System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty dp, object value) + 0x2e bytes        
     PresentationFramework.dll!System.Windows.Data.BindingOperations.SetBinding(System.Windows.DependencyObject target, System.Windows.DependencyProperty dp, System.Windows.Data.BindingBase binding) + 0x39 bytes              
     Xceed.Wpf.DataGrid.dll!Xceed.Wpf.DataGrid.DataCell.SetupDisplayMemberBinding(Xceed.Wpf.DataGrid.DataGridContext dataGridContext = {Xceed.Wpf.DataGrid.DataGridContext}) + 0x170 bytes      
    Xceed.Wpf.DataGrid.dll!Xceed.Wpf.DataGrid.DataCell.InitializeCore(Xceed.Wpf.DataGrid.DataGridContext dataGridContext = {Xceed.Wpf.DataGrid.DataGridContext}, Xceed.Wpf.DataGrid.Row parentRow = {Xceed.Wpf.DataGrid.DataRow}, Xceed.Wpf.DataGrid.Column parentColumn = FieldName = Cannot evaluate expression because a native frame is on top of the call stack.) + 0x8b bytes             
    Xceed.Wpf.DataGrid.dll!Xceed.Wpf.DataGrid.Cell.Initialize(Xceed.Wpf.DataGrid.DataGridContext dataGridContext = {Xceed.Wpf.DataGrid.DataGridContext}, Xceed.Wpf.DataGrid.Row parentRow = {Xceed.Wpf.DataGrid.DataRow}, Xceed.Wpf.DataGrid.Column parentColumn = FieldName = Cannot evaluate expression because a native frame is on top of the call stack.) + 0x96 bytes       
    Xceed.Wpf.DataGrid.dll!Xceed.Wpf.DataGrid.Row.ProvideCell(Xceed.Wpf.DataGrid.Column column = FieldName = Cannot evaluate expression because a native frame is on top of the call stack.) + 0x145 bytes
    Xceed.Wpf.DataGrid.dll!Xceed.Wpf.DataGrid.VirtualizingCellCollection.GetCell(Xceed.Wpf.DataGrid.Column column = FieldName = Cannot evaluate expression because a native frame is on top of the call stack.) + 0x30 bytes   
    Xceed.Wpf.DataGrid.dll!Xceed.Wpf.DataGrid.VirtualizingCellCollection.this[string].get(string fieldName = “FuelType”) + 0x8e bytes           
    Xceed.Wpf.DataGrid.dll!Xceed.Wpf.DataGrid.Views.FixedCellPanel.UpdateScrollingCellPanel(bool allowDispatchOperation = false, Xceed.Wpf.DataGrid.Views.UpdateMeasureTriggeredAction action = Unspecified) + 0x30e bytes   
    Xceed.Wpf.DataGrid.dll!Xceed.Wpf.DataGrid.Views.FixedCellPanel.UpdateChildren(bool allowDispatchOperation = false, Xceed.Wpf.DataGrid.Views.UpdateMeasureTriggeredAction action = Unspecified) + 0x12c bytes       
    Xceed.Wpf.DataGrid.dll!Xceed.Wpf.DataGrid.Views.FixedCellPanel.UpdateChildren(bool allowDispatchOperation = false) + 0x29 bytes     
    Xceed.Wpf.DataGrid.dll!Xceed.Wpf.DataGrid.Views.FixedCellPanel.MeasureOverride(System.Windows.Size availableSize = {System.Windows.Size}) + 0x2e9 bytes
    PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x1d0 bytes     
    PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x1ec bytes               
    PresentationFramework.dll!System.Windows.Controls.Grid.MeasureCell(int cell, bool forceInfinityV) + 0x126 bytes               
    PresentationFramework.dll!System.Windows.Controls.Grid.MeasureCellsGroup(int cellsHead, System.Windows.Size referenceSize, bool ignoreDesiredSizeU = false, bool forceInfinityV = false) + 0x59 bytes           
    PresentationFramework.dll!System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size constraint) + 0x2c9 bytes       
    PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x1d0 bytes     
    PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x1ec bytes               
    PresentationFramework.dll!System.Windows.Controls.Control.MeasureOverride(System.Windows.Size constraint) + 0x7b bytes             
    PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x1d0 bytes     
    PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x1ec bytes               
    Xceed.Wpf.DataGrid.dll!Xceed.Wpf.DataGrid.Views.TableViewItemsHost.MeasureOverride(System.Windows.Size availableSize = {System.Windows.Size}) + 0x7b0 bytes
    PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x1d0 bytes     
    PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x1ec bytes               
    PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayout() + 0x1c4 bytes            
    PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayoutCallback(object arg) + 0x19 bytes               
    PresentationCore.dll!System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork() + 0x10 bytes               
    PresentationCore.dll!System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() + 0x97 bytes  
    PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandlerCore(object resizedCompositionTarget = null) + 0x80 bytes
    PresentationCore.dll!System.Windows.Media.MediaContext.AnimatedRenderMessageHandler(object resizedCompositionTarget) + 0x2b bytes           
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback = {Method = Cannot evaluate expression because a native frame is on top of the call stack.}, object args = null, bool isSingleParameter = true) + 0x8a bytes               
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler = null) + 0x4a bytes           
    WindowsBase.dll!System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler) + 0x44 bytes 
    WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl() + 0x5d bytes           
    WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(object state) + 0x38 bytes   
    mscorlib.dll!System.Threading.ExecutionContext.runTryCode(object userData) + 0x51 bytes 
    [Native to Managed Transition]              
    [Managed to Native Transition]              
    mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x67 bytes      
    mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x45 bytes              
    WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() + 0x63 bytes     
    WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue() + 0x127 bytes        
    WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0x63 bytes 
    WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd = 1381634, int msg = 49991, System.IntPtr wParam = 0, System.IntPtr lParam = 0, ref bool handled = false) + 0xbe bytes   
    WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) + 0x7a bytes         
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback = {Method = Cannot evaluate expression because a native frame is on top of the call stack.}, object args = {MS.Win32.HwndSubclass.DispatcherOperationCallbackParameter}, bool isSingleParameter = true) + 0x8a bytes        
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler = null) + 0x4a bytes           
    WindowsBase.dll!System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler) + 0x44 bytes 
     WindowsBase.dll!System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, bool isSingleParameter) + 0x91 bytes       
    WindowsBase.dll!System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority priority, System.Delegate method, object arg) + 0x40 bytes     
    WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd = 1381634, int msg = 49991, System.IntPtr wParam = 0, System.IntPtr lParam = 0) + 0xdc bytes       
    [Native to Managed Transition]              
    [Managed to Native Transition]              
     WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame = {System.Windows.Threading.DispatcherFrame}) + 0xc7 bytes               
     WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame) + 0x49 bytes      
    WindowsBase.dll!System.Windows.Threading.Dispatcher.Run() + 0x4c bytes 
    PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore) + 0x1e bytes              
    PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) + 0x6f bytes   
    PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window) + 0x26 bytes               
    PresentationFramework.dll!System.Windows.Application.Run() + 0x19 bytes
    ArcLogistics.App.exe!ArcLogistics.App.App.Main() + 0x94 bytes         C#
    [Native to Managed Transition]              
    [Managed to Native Transition]              
    mscorlib.dll!System.AppDomain.nExecuteAssembly(System.Reflection.Assembly assembly, string[] args) + 0x19 bytes   
    mscorlib.dll!System.Runtime.Hosting.ManifestRunner.Run(bool checkAptModel) + 0x6e bytes           
    mscorlib.dll!System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() + 0x84 bytes     
    mscorlib.dll!System.Runtime.Hosting.ApplicationActivator.CreateInstance(System.ActivationContext activationContext, string[] activationCustomData) + 0x65 bytes             
    mscorlib.dll!System.Runtime.Hosting.ApplicationActivator.CreateInstance(System.ActivationContext activationContext) + 0xa bytes
    mscorlib.dll!System.Activator.CreateInstance(System.ActivationContext activationContext) + 0x3e bytes       
     Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() + 0x23 bytes     
    mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x66 bytes              
    mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x6f bytes              
    mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x44 bytes

    Please let me know if you need more information.

    Thanks,
    Anatoly

    Imported from legacy forums. Posted by Anatoly (had 772 views)

    Xceed Support
    Member
    Post count: 5658

    I have created a ticket for this issue and a developer will be taking a look at it to see what is going on. In the meantime, if you have any new information, please feel free to post it here.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 3434 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Anatoly,

    Would you be able to send us a repro app? I am not able to reproduce your issue here and I would like to see how your grid and your binding are defined.

    Thanks.

    Imported from legacy forums. Posted by Jacques [Xceed] (had 2709 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Anatoly,

    I’ve been working on the issue and I believe the problem comes from the SqlCeConnection used by the ObjectContext of EntityFramework. I’ve found a ticket on Microsoft Connect which describe exactly the problem you are experiencing. 

    Unfortunately, there are no workaround at the moment and they say that a fix should be available in a futur release.

    Here’s the link of the ticket, if you want to follow it.

    https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=411912&wa=wsignin1.0

    Imported from legacy forums. Posted by Jacques [Xceed] (had 3869 views)

    Sas
    Participant
    Post count: 13

    I don’t know if it can help.
    I had ContextSwitchDeadlock or Out of Memory error when loading large datas from Oracle to the Datagrid.
    I was because my grid was in a StackPanel…
    Regards

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.