Exception when changing DataContext

6 posts, 1 answers
  1. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 06 Oct 2010 Link to this post

    Hi,

    I'm using multiple sliders in a window, with customized Tick template. Sometimes when I change the DataContext I get following "Object reference not set to an instance of an object." exception:

    at Telerik.Windows.Controls.RadTickBar.LoadTemplate(Double tickValue) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP1\Sources\Development\Core\Controls\Slider\RadTickBar.cs:line 402
    at Telerik.Windows.Controls.RadTickBar.CreateTick(Double tickValue) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP1\Sources\Development\Core\Controls\Slider\RadTickBar.cs:line 352
    at Telerik.Windows.Controls.RadTickBar.DrawTicks() in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP1\Sources\Development\Core\Controls\Slider\RadTickBar.cs:line 231
    at Telerik.Windows.Controls.RadSlider.RedrawTicks() in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP1\Sources\Development\Core\Controls\Slider\RadSlider.cs:line 2904
    at Telerik.Windows.Controls.RadSlider.OnMaximumChanged(Double oldMaximum, Double newMaximum) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP1\Sources\Development\Core\Controls\Slider\RadSlider.cs:line 1448
    at System.Windows.Controls.Primitives.RangeBase.OnMaximumChanged(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, OperationType operationType)
    at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp)
    at System.Windows.Data.BindingExpression.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.OnDataContextChanged(DependencyObject contextElement)
    at System.Windows.Data.BindingExpression.HandlePropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
    at System.Windows.Data.BindingExpression.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
    at System.Windows.DependentList.InvalidateDependents(DependencyObject source, DependencyPropertyChangedEventArgs sourceArgs)
    at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
    at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
    at System.Windows.TreeWalkHelper.OnInheritablePropertyChanged(DependencyObject d, InheritablePropertyChangeInfo info)
    at System.Windows.DescendentsWalker`1._VisitNode(DependencyObject d)
    at System.Windows.DescendentsWalker`1.VisitNode(FrameworkElement fe)
    at System.Windows.DescendentsWalker`1.VisitNode(DependencyObject d)
    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)
    at System.Windows.DescendentsWalker`1.VisitNode(FrameworkElement fe)
    at System.Windows.DescendentsWalker`1.VisitNode(DependencyObject d)
    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 System.Windows.TreeWalkHelper.InvalidateOnInheritablePropertyChange(FrameworkElement fe, FrameworkContentElement fce, InheritablePropertyChangeInfo info, Boolean skipStartNode)
    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, OperationType operationType)
    at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
    at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
    at System.Windows.FrameworkElement.set_DataContext(Object value)



    Do you guys think you can provide a quick fix for this?

    Thank you,
    Ruben
  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 12 Oct 2010 Link to this post

    Hello Ruben,

    I've tried to reproduce this issue but in vain. Could you please take a look at the attached project and let me know if I am missing something.

    Sincerely yours,
    Kiril Stanoev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 12 Oct 2010 Link to this post

    Hi Kiril,

    I'm looking to your sample and indeed it looks normal. It does not like to be a simple task to reproduce this exception in a sample application. However, this exception keeps happening in my application constantly. 

    Did you have a chance to take a look to RadTickBar.LoadTemplate function and see if there is anything suspicious on line 402?

    Thanks,
    Ruben
  5. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 12 Oct 2010 Link to this post

    Hi Kiril,

    With TickPlacement="None" I have not noticed any exceptions. 
    I was just thinking if it is possible to protect RadTickBar.LoadTemplate method
    with try..catch clause and perform some debug output in the
    exception handle. With this updated version it would be easier
    to diagnose the issue.

    Thank you,
    Ruben

  6. Answer
    Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 14 Oct 2010 Link to this post

    Hi Ruben,

    This is how line 402 looks like in our code. In my opinion there is nothing suspicious.



    There is no problem to surround the LoadContent() call with a try/catch block. This will be done for our official Q3 release. Meanwhile, if you manage to narrow the cause for the error, I'd be glad if you share your approach with me.

    Kind regards,
    Kiril Stanoev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Ruben Hakopian
    Ruben Hakopian avatar
    37 posts
    Member since:
    Nov 2009

    Posted 08 Nov 2010 Link to this post

    This issue was fixed in internal build version 2010.2.1022.35.
Back to Top
UI for WPF is Visual Studio 2017 Ready