Bad exception when closing the containing window

I’m using MVVM pattern in a wpf application, when I close a window that contains a video player.

i got the following exception

at VideoOS.UI.Common.WPF.VideoPlayer.Control.UI.ImageOverlay.ImageOverlayContainer.ImageOverlayContainer_OnDataContextChanged(Object sender, DependencyPropertyChangedEventArgs e)

at System.Windows.FrameworkElement.RaiseDependencyPropertyChanged(EventPrivateKey key, DependencyPropertyChangedEventArgs args)

at System.Windows.FrameworkElement.OnDataContextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)

at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)

at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)

at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)

at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)

at System.Windows.TreeWalkHelper.InvalidateTreeDependentProperty(TreeChangeInfo info, DependencyObject d, FrameworkObject& fo, DependencyProperty dp, FrameworkPropertyMetadata fMetadata, Style selfStyle, Style selfThemeStyle, ChildRecord& childRecord, Boolean isChildRecordValid, Boolean hasStyleChanged, Boolean isSelfInheritanceParent, Boolean wasSelfInheritanceParent)

at System.Windows.TreeWalkHelper.InvalidateTreeDependentProperties(TreeChangeInfo info, FrameworkElement fe, FrameworkContentElement fce, Style selfStyle, Style selfThemeStyle, ChildRecord& childRecord, Boolean isChildRecordValid, Boolean hasStyleChanged, Boolean isSelfInheritanceParent, Boolean wasSelfInheritanceParent)

at System.Windows.FrameworkElement.InvalidateTreeDependentProperties(TreeChangeInfo parentTreeState, Boolean isSelfInheritanceParent, Boolean wasSelfInheritanceParent)

at System.Windows.FrameworkElement.OnAncestorChangedInternal(TreeChangeInfo parentTreeState)

at System.Windows.TreeWalkHelper.OnAncestorChanged(DependencyObject d, TreeChangeInfo info, Boolean visitedViaVisualTree)

at System.Windows.DescendentsWalker`1._VisitNode(DependencyObject d, Boolean visitedViaVisualTree)

at MS.Internal.PrePostDescendentsWalker`1._VisitNode(DependencyObject d, Boolean visitedViaVisualTree)

at System.Windows.DescendentsWalker`1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren)

at System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren)

at System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d)

at System.Windows.DescendentsWalker`1._VisitNode(DependencyObject d, Boolean visitedViaVisualTree)

at MS.Internal.PrePostDescendentsWalker`1._VisitNode(DependencyObject d, Boolean visitedViaVisualTree)

at System.Windows.DescendentsWalker`1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren)

at System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren)

at System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d)

at System.Windows.DescendentsWalker`1.StartWalk(DependencyObject startNode, Boolean skipStartNode)

at MS.Internal.PrePostDescendentsWalker`1.StartWalk(DependencyObject startNode, Boolean skipStartNode)

at System.Windows.TreeWalkHelper.InvalidateOnTreeChange(FrameworkElement fe, FrameworkContentElement fce, DependencyObject parent, Boolean isAddOperation)

at System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)

at System.Windows.FrameworkElement.RemoveLogicalChild(Object child)

at System.Windows.Controls.ContentControl.OnContentChanged(Object oldContent, Object newContent)

at System.Windows.Controls.ContentControl.OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)

at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)

at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)

at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)

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.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)

at Telerik.Windows.Controls.RadTileView.ClearUserControls(RadTileViewItem container)

at Telerik.Windows.Controls.RadTileView.ClearContainerForItemOverride(DependencyObject element, Object item)

at System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.ClearContainerForItem(DependencyObject container, Object item)

at System.Windows.Controls.ItemContainerGenerator.UnlinkContainerFromItem(DependencyObject container, Object item, IGeneratorHost host)

at System.Windows.Controls.ItemContainerGenerator.RemoveAllInternal(Boolean saveRecycleQueue)

at System.Windows.Controls.ItemContainerGenerator.OnRefresh()

at System.Windows.Controls.ItemContainerGenerator.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)

at System.Windows.WeakEventManager.ListenerList`1.DeliverEvent(Object sender, EventArgs e, Type managerType)

at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)

at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)

at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)

at System.Windows.WeakEventManager.ListenerList`1.DeliverEvent(Object sender, EventArgs e, Type managerType)

at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)

at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)

at System.Windows.Data.ListCollectionView.RefreshOverride()

at System.Windows.Data.CollectionView.RefreshInternal()

at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)

at Catel.Collections.FastObservableCollection`1.<>c__DisplayClass32_0.b__0() in [C:\CI_WS\Ws\113423\Source\Catel\src\Catel.MVVM\Collections\FastObservableCollection.cs](file:C:/CI_WS/Ws/113423/Source/Catel/src/Catel.MVVM/Collections/FastObservableCollection.cs):line 458

at Catel.Windows.Threading.DispatcherExtensions.BeginInvoke(Dispatcher dispatcher, Action action, Boolean onlyBeginInvokeWhenNoAccess) in [C:\CI_WS\Ws\113423\Source\Catel\src\Catel.MVVM\Windows\Threading\Extensions\DispatcherExtensions.begininvoke.cs](file:C:/CI_WS/Ws/113423/Source/Catel/src/Catel.MVVM/Windows/Threading/Extensions/DispatcherExtensions.begininvoke.cs):line 115

at Catel.Collections.FastObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e) in [C:\CI_WS\Ws\113423\Source\Catel\src\Catel.MVVM\Collections\FastObservableCollection.cs](file:C:/CI_WS/Ws/113423/Source/Catel/src/Catel.MVVM/Collections/FastObservableCollection.cs):line 458

at Catel.Collections.FastObservableCollection`1.b__31_0() in [C:\CI_WS\Ws\113423\Source\Catel\src\Catel.MVVM\Collections\FastObservableCollection.cs](file:C:/CI_WS/Ws/113423/Source/Catel/src/Catel.MVVM/Collections/FastObservableCollection.cs):line 433

at Catel.Windows.Threading.DispatcherExtensions.BeginInvoke(Dispatcher dispatcher, Action action, Boolean onlyBeginInvokeWhenNoAccess) in [C:\CI_WS\Ws\113423\Source\Catel\src\Catel.MVVM\Windows\Threading\Extensions\DispatcherExtensions.begininvoke.cs](file:C:/CI_WS/Ws/113423/Source/Catel/src/Catel.MVVM/Windows/Threading/Extensions/DispatcherExtensions.begininvoke.cs):line 115

at Catel.Collections.FastObservableCollection`1.NotifyChanges() in [C:\CI_WS\Ws\113423\Source\Catel\src\Catel.MVVM\Collections\FastObservableCollection.cs](file:C:/CI_WS/Ws/113423/Source/Catel/src/Catel.MVVM/Collections/FastObservableCollection.cs):line 440

at Catel.Collections.FastObservableCollection`1.<>c.b__30_1(IDisposableToken`1 x) in [C:\CI_WS\Ws\113423\Source\Catel\src\Catel.MVVM\Collections\FastObservableCollection.cs](file:C:/CI_WS/Ws/113423/Source/Catel/src/Catel.MVVM/Collections/FastObservableCollection.cs):line 408

at Catel.DisposableToken`1.Dispose() in [C:\CI_WS\Ws\113423\Source\Catel\src\Catel.Core\DisposableToken.cs](file:C:/CI_WS/Ws/113423/Source/Catel/src/Catel.Core/DisposableToken.cs):line 82

at Orchestra.Examples.Ribbon.ViewModels.MainViewModel.<>c__DisplayClass37_0.<b__0>d.MoveNext() in [C:\projects\HMSFDSCom\src\HMSFDSCom\ViewModels\MainViewModel.cs](file:C:/projects/HMSFDSCom/src/HMSFDSCom/ViewModels/MainViewModel.cs):line 165

How can I avoid this? consider I’m invoking the close on viewmodel which disconnects the video stream from milestone server

Since you are not writing which exception it is you are seeing I cannot say for sure, but if you add the following to your Window’s Closed event handler it will hopefully solve it:

       \_imageViewerControl.Disconnect();

       \_imageViewerControl.Close();

       \_imageViewerControl.Dispose();

youre right… I got a NullReference exception and I’m just performing such commanda (Disconnect/Close/Dispose)

Il Gio 9 Ago 2018, 15:05 Milestone Developer Forum <noreply@milestonesys.com> ha scritto:

So you are calling the three methods, but are still getting the null reference exception?

We have not seen this before (and are also using the underlying control internally in our Smart Client), so I wonder whether you do something special/extra with the ImageViewer control? Would it be possible for you to provide some sample application that reproduces this - maybe based on the PlaybackWpfUser sample?

I’ve created a sample based on my source code (I’m on vacation with a 3mb/512kb wimax, so everything takes a lot to do). just click on the add button, even if a error of the camera appears, don’t mind it. click on the close button and you’ll see the exception on console it’s the same that appears in my app.

The problem is that even if it’s under try catch if you open 2 video instances then close, the whole app closes

Here’s the drive’s link (.rar compressed… 54mb)

https://drive.google.com/open?id=1aYbNnz6kb6YoCJy6t6Guxo3Y7UqU2Fn4

Thank you for the sample. It allowed us to reproduce the issue, but unfortunately the behavior we observe is quite strange.

What appears to happen is that the DataContext on the controls we have inside the ImageViewerWpfControl are set to null by something outside our code. Our code has no code for setting these to null and no public properties allowing others to do so, so apparently Telerik is running through the children of the control and setting these?

We tried reproducing using normal WPF controls, but could not.

This is not behavior we expect/support and thus the code has not been designed for it.

One thing we found out is that if you set IsVirtualizing=“False” on the Telerik control it will not cause the problem, so even though this is not optimal it is at least a workaround.

Maybe you can reach out to Telerik to ask them about this behavior?

Excuse me Peter,

I’ve got the answer (https://www.telerik.com/forums/exception-when-using-videoos-inside-tileview) by Telerik

So I’ll turn off virtualization

Thanks

Posted 5 minutes ago

Link to this post

Hello Paolo,

Indeed, when the control’s UI virtualization is enabled the content of the tileviewitem removed from the viewport will be cleared. This is why the context of the ImageViewerWpfControl is set to null and the exception is thrown. To resolve this you can disable the UI virtualization as suggested by the Milestone team. To do this set the IsVirtualizing property of RadTileView to False.

Regards,

Martin Ivanov

Progress Telerik