This is a migrated thread and some comments may be shown as answers.

Exception when changing DataContext

5 Answers 93 Views
Slider
This is a migrated thread and some comments may be shown as answers.
Ruben Hakopian
Top achievements
Rank 1
Ruben Hakopian asked on 06 Oct 2010, 08:00 PM
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

5 Answers, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 12 Oct 2010, 09:17 AM
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
0
Ruben Hakopian
Top achievements
Rank 1
answered on 12 Oct 2010, 11:07 PM
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
0
Ruben Hakopian
Top achievements
Rank 1
answered on 12 Oct 2010, 11:24 PM
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

0
Accepted
Kiril Stanoev
Telerik team
answered on 14 Oct 2010, 09:00 AM
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
0
Ruben Hakopian
Top achievements
Rank 1
answered on 08 Nov 2010, 10:04 PM
This issue was fixed in internal build version 2010.2.1022.35.
Tags
Slider
Asked by
Ruben Hakopian
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Ruben Hakopian
Top achievements
Rank 1
Share this question
or