NullReferenceException when changing the selected date

10 posts, 0 answers
  1. Lubch
    Lubch avatar
    11 posts
    Member since:
    Apr 2011

    Posted 29 Sep 2011 Link to this post

    Hi.
    I use RadCalendar in my project for selection date.

    <telerik:RadCalendar HeaderVisibility="Collapsed" Height="150"
                  SelectableDateStart="{Binding SelectedDateStart}"
                  SelectableDateEnd="{Binding SelectedDateEnd}"
                  SelectedDate="{Binding Date, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
    public class NextActionDate : INotifyPropertyChanged
    {
        public DateTime SelectedDateStart { get; set; }
        public DateTime SelectedDateEnd { get; set; }
     
        private DateTime date;
        public DateTime Date
        {
            get
            {
                return date;
            }
            set
            {
                date = value;
                GenerateEvent("Date");
            }
        }
     
        public event PropertyChangedEventHandler PropertyChanged;
        private void GenerateEvent(string inName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(inName));
            }
        }
    }

    Usually it works correctly.

    But sometimes I have exceptions:
    1. System.NullReferenceException: Object reference not set to an instance of an object. at Telerik.Windows.WeakReferenceList`1.CopyTo(T[] array, Int32 arrayIndex) at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at Telerik.Windows.Controls.SelectionChanger`1.BuildSelectionChangedEventArgs() at Telerik.Windows.Controls.SelectionChanger`1.End() at Telerik.Windows.Controls.SelectionChanger`1.AddJustThis(T item) at Telerik.Windows.Controls.RadCalendar.AddToSelection(DateTime selectedDate, Boolean controlKeyDown, Boolean shiftKeyDown) at Telerik.Windows.Controls.RadCalendar.Select(DateTime selectedDate, Boolean forceSelection) at Telerik.Windows.Controls.Calendar.CalendarView.AddDate(Object sender) at Telerik.Windows.Controls.Calendar.CalendarView.HandleMouseEvents(Object sender, MouseButtonEventArgs e) at Telerik.Windows.Controls.Calendar.CalendarView.CalendarButtonMouseLeftButtonDown(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent) at System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at System.Windows.Interop.HwndSource.InputFilterMessage(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)

    2. System.NullReferenceException: Object reference not set to an instance of an object. at Telerik.Windows.WeakReferenceList`1.WeakReferenceEnumerator.get_Current() at Telerik.Windows.Controls.SelectionChanger`1.SynchronizeInternalSelection() at Telerik.Windows.Controls.SelectionChanger`1.End() at Telerik.Windows.Controls.SelectionChanger`1.AddJustThis(T item) at Telerik.Windows.Controls.RadCalendar.AddToSelection(DateTime selectedDate, Boolean controlKeyDown, Boolean shiftKeyDown) at Telerik.Windows.Controls.RadCalendar.Select(DateTime selectedDate, Boolean forceSelection) at Telerik.Windows.Controls.Calendar.CalendarView.AddDate(Object sender) at Telerik.Windows.Controls.Calendar.CalendarView.HandleMouseEvents(Object sender, MouseButtonEventArgs e) at Telerik.Windows.Controls.Calendar.CalendarView.CalendarButtonMouseLeftButtonDown(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent) at System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at System.Windows.Interop.HwndSource.InputFilterMessage(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)

    3. System.NullReferenceException: Object reference not set to an instance of an object. at Telerik.Windows.WeakReferenceList`1.IndexOf(T item) at Telerik.Windows.WeakReferenceList`1.Remove(T item) at Telerik.Windows.Controls.SelectionChanger`1.Select(T item) at Telerik.Windows.Controls.SelectionChanger`1.InsertItem(Int32 index, T item) at System.Collections.ObjectModel.Collection`1.Add(T item) at Telerik.Windows.Controls.SelectionChanger`1.AddJustThis(T item) at Telerik.Windows.Controls.RadCalendar.AddToSelection(DateTime selectedDate, Boolean controlKeyDown, Boolean shiftKeyDown) at Telerik.Windows.Controls.RadCalendar.Select(DateTime selectedDate, Boolean forceSelection) at Telerik.Windows.Controls.Calendar.CalendarView.AddDate(Object sender) at Telerik.Windows.Controls.Calendar.CalendarView.HandleMouseEvents(Object sender, MouseButtonEventArgs e) at Telerik.Windows.Controls.Calendar.CalendarView.CalendarButtonMouseLeftButtonDown(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent) at System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at System.Windows.Interop.HwndSource.InputFilterMessage(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)

    Control in exception moment - http://sound-fresh.com/radcalendar.png

    Thanks you.
  2. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 03 Oct 2011 Link to this post

    Hello Lubch,

    We tried to reproduce this issue without any success. It would be great if you find out when this is happening so we could investigate it further.

    Best wishes,
    Ivo
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Lubch
    Lubch avatar
    11 posts
    Member since:
    Apr 2011

    Posted 04 Oct 2011 Link to this post

    I don't know  when this is happening. I have only report about exception (via DispatcherUnhandledException), which I sent you.

    It happening on OS Windows XP SP3, .Net Framework 4.0, telerik version 2011.1.419.35
    It's all.
  5. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 05 Oct 2011 Link to this post

    Hi Lubch,

    Thank you for your feedback.

    However we cannot reproduce it, so it is impossible to investigate it further.

    Best wishes,
    Ivo
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Brian
    Brian avatar
    9 posts
    Member since:
    Dec 2008

    Posted 07 Nov 2011 Link to this post

    We are having the same issue.  Seems to be happening randomly.  We are running Windows 7, Windows Vista, .NET 3.5 Framework.
    Telerik Version 2011.2.0920.35.  As you can we are not subscribing to events, no triggers and no formatting on the DatePicker.

    XAML Code
     

     

    <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal">
        <TextBlock Style="{StaticResource textBlockRight}" Text="Balance To Pay:  "/>
        <ComboBox x:Name="cbBalanceToPay" Style="{StaticResource comboBoxLeft}" Width="120"/>
        <TextBlock Style="{StaticResource textBlockRight}" Text="    Start:  "/>
        <telerik:RadDatePicker x:Name="startDate" Width="90" FontSize="12" Height="25" Foreground="Black"  />
        <TextBlock Style="{StaticResource textBlockRight}" Text="    Frequency:  "/>
        <ComboBox Style="{StaticResource comboBoxLeft}" Width="135" x:Name="payFrequencies"  ItemTemplate="{StaticResource payFrequencyTemplate}" SelectionChanged="payFrequencies_SelectionChanged"/>
    </StackPanel>

     

     

     

     

    code causing the error 

    if (startDate.SelectedDate == null || startDate.SelectedDate <= DateTime.Now.Date)
    {
        if (mAccount.PaymentSchedule.Count > 0 && mAccount.PaymentSchedule[0].PaymentDate.Date > DateTime.Now.Date)
        {
            startDate.SelectedDate = mAccount.PaymentSchedule[0].PaymentDate;
        }
        else
        {
            startDate.SelectedDate = mAccount.CalculateStartPaymentDate(true);
        }
    }


    Object reference not set to an instance of an object.

    Machine Name: KMAMALES

    Parameters : accountId = 543530

    Stack Trace:    at Telerik.Windows.WeakReferenceList`1.WeakReferenceEnumerator.get_Current()

       at Telerik.Windows.Controls.SelectionChanger`1.SynchronizeInternalSelection()

       at Telerik.Windows.Controls.SelectionChanger`1.End()

       at Telerik.Windows.Controls.SelectionChanger`1.AddJustThis(T item)

       at Telerik.Windows.Controls.RadCalendar.AddToSelection(DateTime selectedDate, Boolean controlKeyDown, Boolean shiftKeyDown)

       at Telerik.Windows.Controls.RadCalendar.OnSelectedDateChanged(DependencyObject sender, 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.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.ScheduleTransfer(Boolean isASubPropertyChange)

       at MS.Internal.Data.ClrBindingWorker.NewValueAvailable(Boolean dependencySourcesChanged, Boolean initialValue, Boolean isASubPropertyChange)

       at MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k, ICollectionView collectionView, Object newValue, Boolean isASubPropertyChange)

       at MS.Internal.Data.PropertyPathWorker.OnDependencyPropertyChanged(DependencyObject d, DependencyProperty dp, Boolean isASubPropertyChange)

       at MS.Internal.Data.ClrBindingWorker.OnSourceInvalidation(DependencyObject d, DependencyProperty dp, Boolean isASubPropertyChange)

       at System.Windows.Data.BindingExpression.HandlePropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)

       at System.Windows.Data.BindingExpressionBase.OnPropertyInvalidation(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, Boolean coerceWithCurrentValue, OperationType operationType)

       at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)

       at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)

       at TANC.RTOEditPaySchedule.PopulateControl(Account account) in C:\Development\Progressive\TANC\RTOEditPaySchedule.xaml.cs:line 206 ================================================================================

  7. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 10 Nov 2011 Link to this post

    Hello Brian,

    We fixed similar issue, so it would be great if you test this with the latest internal build of RadControls for WPF and post the result here.

    Kind regards,
    Ivo
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. Peter
    Peter avatar
    5 posts
    Member since:
    May 2010

    Posted 05 Dec 2011 Link to this post

    We experience the exact same issue.
    It seems like this occasionally happens if you try to change for instance the SelectedValue of a Calendar (e.g. Date/TimePicker) in code-behind while the property has a binding defined in XAML. I'm aware that this is not a good practice and we will work on getting rid of this scenario but maybe this info can help you guys to narrow down the issue.
  9. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 05 Dec 2011 Link to this post

    Hi Peter,

    I tested this using three different versions of RadControls for WPF: 2011 Q2, 2011 Q2 SP1 and 2011 Q3. I could not reproduce what you have described. You can find attached project of what I tried. Could you point if I am doung something wrong?

    All the best,
    Ivo
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  10. Peter
    Peter avatar
    5 posts
    Member since:
    May 2010

    Posted 05 Dec 2011 Link to this post

    To be honest I can't reproduce it myself but our users very rarely stumble accross this issue and from the stacktraces we gathered we figured out that this always happens in scenarios like I described above...

    I guess this is a tricky issue to pin down...so I'm currently working on avoiding these scenarios...
  11. Lubch
    Lubch avatar
    11 posts
    Member since:
    Apr 2011

    Posted 05 Dec 2011 Link to this post

    In my project I do not change the SelectedValue in code-behind. All work with binding.
    This issue impossible to reproduce, but our user sometime have exception.

    But if in Application_DispatcherUnhandledException (DispatcherUnhandledException event) e.Handled set to True, the program continue work successfully, except that the SelectedDate do not to change!
Back to Top
UI for WPF is Visual Studio 2017 Ready