Unpredictable exception in DateTimePicker

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

    Posted 08 Apr 2011 Link to this post

    Hi.
    I need show after day in calendar some number.
    This my sources:
    <telerik:RadDateTimePicker>
        <telerik:RadDateTimePicker.CalendarStyle>
            <Style TargetType="{x:Type telerik:RadCalendar}">
                <Setter Property="DayTemplateSelector" Value="{StaticResource CalendarCountTask}"/>
            </Style>
        </telerik:RadDateTimePicker.CalendarStyle>
    </telerik:RadDateTimePicker>
    <a:CustomTemplateSelector x:Key="CalendarCountTask">
        <a:CustomTemplateSelector.DefaultTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Text}"/>
            </DataTemplate>
        </a:CustomTemplateSelector.DefaultTemplate>
        <a:CustomTemplateSelector.CustomTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Text}" Foreground="RoyalBlue"/>
            </DataTemplate>
        </a:CustomTemplateSelector.CustomTemplate>
    </a:CustomTemplateSelector
    public class CustomTemplateSelector : DataTemplateSelector
    {
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            CalendarButtonContent content = item as CalendarButtonContent;
            foreach (KeyValuePair<DateTime, short> oneDay in winDebtorInfo.TaskCountList)
            {
                if (oneDay.Key == content.Date)
                {
                    content.Text += "(" + oneDay.Value + ")";
                    return CustomTemplate;
                }
            }
            return DefaultTemplate;
        }
     
        public DataTemplate DefaultTemplate
        {
            get;
            set;
        }
     
        public DataTemplate CustomTemplate
        {
            get;
            set;
        }
    }
    >

    winDebtorInfo.TaskCountList is source for days, for which there is number for showing.

    This working, but sometimes there is exception:

    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)

    What would it be?
    Thank you.

  2. Lubch
    Lubch avatar
    11 posts
    Member since:
    Apr 2011

    Posted 08 Apr 2011 Link to this post

    I have one more call stack:

    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)

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

    Posted 11 Apr 2011 Link to this post

    And one more:
    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)

    Exception in Telerik.Windows.WeakReferenceList, but call stack is different.
  5. George
    Admin
    George avatar
    1332 posts

    Posted 15 Apr 2011 Link to this post

    Hello,

    Could you please give us more information in what circumstances this exception happens?

    What version of RadControls do you use? If you don't use the latest Q1 assemblies, I would suggest updating and giving it a try.

    Regards,
    George
    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
  6. Lubch
    Lubch avatar
    11 posts
    Member since:
    Apr 2011

    Posted 15 Apr 2011 Link to this post

    Hello.
    I'm use 2010.3.1110.35 version of assembly.
    The trouble is that the exception occurs on the client. I have only report about exception.

    Maybe, you show me how i can show some number after day in calendar? Otherwise, not as in my example.
    Thank you.

    I need make this.
  7. Pana
    Admin
    Pana avatar
    748 posts

    Posted 21 Apr 2011 Link to this post

    Hello,

    Please check the attached project. It uses a multi converter to find the proper data from an outside source using the current button's context. It uses multi converter and selector to display the proper templates.

    All the best,
    Pana
    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
  8. Lubch
    Lubch avatar
    11 posts
    Member since:
    Apr 2011

    Posted 21 Apr 2011 Link to this post

    Thank you very much!
    This is that I need.
  9. Lubch
    Lubch avatar
    11 posts
    Member since:
    Apr 2011

    Posted 26 Apr 2011 Link to this post

    It works exactly the same, having the same exceptions.
    The Problem is open.
    I'm waiting for your help.
  10. Pana
    Admin
    Pana avatar
    748 posts

    Posted 02 May 2011 Link to this post

    Hello Lubch,

    We will further reserch this issue.

    Greetings,
    Pana
    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
  11. Oleg
    Oleg avatar
    3 posts
    Member since:
    Sep 2015

    Posted 29 Oct 2015 in reply to Lubch Link to this post

    Hi, same exception

    to Telerik team:

    Its definitely a bug in code

    Type: Telerik.Windows.WeakReferenceList`1

    Assembly: Telerik.Windows.Controls, Version=2013.3.1204.1050

    method:

    public int IndexOf(T item)
       {
         EqualityComparer<T> @default = EqualityComparer<T>.Default;
         for (int index = 0; index < this.items.Count; ++index)
         {
           if (@default.Equals((T) this.items[index].Target, item))
             return index;
         }
         return -1;
       }
      

     problem is here: (T) this.items[index].Target

    during garbage  collection this.items[index].Target can be Null and  (T) this.items[index].Target throws NullReferenceException

    see https://msdn.microsoft.com/en-us/library/yz2be5wk.aspx

    "Attempting to unbox null causes a NullReferenceException"

    you can reproduce this by code

    var dt = DateTime.Now;
    var wrl = new WeakReferenceList<DateTime>();
    wrl.Add(dt);
    GC.Collect();
    wrl.IndexOf(dt);

     possible solution 

    var itemAtIndex = this._items[index];
     var target = itemAtIndex.IsAlive ? (T)itemAtIndex.Target : default(T);
    if (@default.Equals(target, item))
                         

  12. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 02 Nov 2015 Link to this post

    Hello Oleg,

    You are correct that WeakReferenceList collection is throwing an execution in this scenario. However as the collection is internal - can you please share some more details on how exactly you were able to hit the exception? Was it thrown from the DateTimePicker and if so - can you share the exact scenario?

    I'm looking forward to hearing from you.

    Regards,
    Kalin
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  13. Markus Stehle
    Markus Stehle avatar
    5 posts
    Member since:
    Sep 2007

    Posted 09 Nov 2015 Link to this post

    Hi,

    we've got the same issue. When will it be fixed?

  14. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 10 Nov 2015 Link to this post

    Hello Markus,

    Can you share more details regarding the exact steps to reproduce the mentioned exception? Can you provide a sample project demonstrating the scenario?

    I'm looking forward to hearing from you.

    Regards,
    Kalin
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  15. Markus Stehle
    Markus Stehle avatar
    5 posts
    Member since:
    Sep 2007

    Posted 10 Nov 2015 in reply to Kalin Link to this post

    Hello Kalin,

    no, sorry. I just see exactly the same exception in our log. 

  16. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 13 Nov 2015 Link to this post

    Hi Markus,

    Can you share some more details regarding the exact setup of the DateTimePicker or Calendar that is possibly throwing that exception? This way we will try to reproduce it on our side and further investigate the issue.

    I'm looking forward to hearing from you.

    Regards,
    Kalin
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  17. Markus Stehle
    Markus Stehle avatar
    5 posts
    Member since:
    Sep 2007

    Posted 16 Nov 2015 in reply to Kalin Link to this post

    Hi Kalin,

    we just use the default settings and a binding on the SelectedValue Property.

     

    Regards,

    Markus

  18. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 19 Nov 2015 Link to this post

    Hi Markus,

    We will further investigate the issue and will try to reproduce it on our side. However any addition information would be helpful - binaries version, OS version and other details regarding the machine where the exception was reproduced? Where is the control placed - is it inside some panel that is being collapsed? Meanwhile if you manage to isolate the issue you can send us a sample project demonstrating the scenario.

    Regards,
    Kalin
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready