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

Unpredictable exception in DateTimePicker

18 Answers 229 Views
DateTimePicker
This is a migrated thread and some comments may be shown as answers.
Lubch
Top achievements
Rank 1
Lubch asked on 08 Apr 2011, 02:11 PM
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.

18 Answers, 1 is accepted

Sort by
0
Lubch
Top achievements
Rank 1
answered on 08 Apr 2011, 03:39 PM
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)

0
Lubch
Top achievements
Rank 1
answered on 11 Apr 2011, 07:28 AM
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.
0
George
Telerik team
answered on 15 Apr 2011, 08:58 AM
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
0
Lubch
Top achievements
Rank 1
answered on 15 Apr 2011, 09:15 AM
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.
0
Pana
Telerik team
answered on 21 Apr 2011, 02:33 PM
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
0
Lubch
Top achievements
Rank 1
answered on 21 Apr 2011, 03:26 PM
Thank you very much!
This is that I need.
0
Lubch
Top achievements
Rank 1
answered on 26 Apr 2011, 02:23 PM
It works exactly the same, having the same exceptions.
The Problem is open.
I'm waiting for your help.
0
Pana
Telerik team
answered on 02 May 2011, 12:04 PM
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
0
Oleg
Top achievements
Rank 1
answered on 29 Oct 2015, 12:35 PM

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))
                     

0
Kalin
Telerik team
answered on 02 Nov 2015, 11:28 AM
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
0
Markus Stehle
Top achievements
Rank 1
answered on 10 Nov 2015, 05:24 AM

Hi,

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

0
Kalin
Telerik team
answered on 10 Nov 2015, 07:46 AM
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
0
Markus Stehle
Top achievements
Rank 1
answered on 10 Nov 2015, 08:17 AM

Hello Kalin,

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

0
Kalin
Telerik team
answered on 13 Nov 2015, 08:09 AM
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
0
Markus Stehle
Top achievements
Rank 1
answered on 16 Nov 2015, 01:57 PM

Hi Kalin,

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

 

Regards,

Markus

0
Kalin
Telerik team
answered on 19 Nov 2015, 09:07 AM
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
0
Susmitha
Top achievements
Rank 1
Veteran
Iron
answered on 06 Jul 2020, 08:43 AM

Hi Kalin,

I have an issue some thing similar to this.

I was using an older version of Telerik (2013.2.724.40) and I used RadDateTimePicker with (InputMode="DatePicker") in my WPF UI ,it was working fine without any problems.

Now I upgraded to Telerik version (2019.3.917.40) and on click on the dots of RadDateTimePicker to select the date its giving null reference exception & this is happening only on the first time.After this exception I am able to change the date.

Could you please share some insights on this issue?

Thanks & Regards

Susmitha

0
Vladimir Stoyanov
Telerik team
answered on 09 Jul 2020, 07:37 AM

Hello Susmitha,

Thank you for the shared information. 

I tried to replicate the scenario in a sample project on my end, however I was not able to do so (I tested with the 2019.3.917.40 version). Can you check out the shared project and let me know, if I am missing something?

If you find it possible, you can update the project in order to reproduce the exception and send it over in a new support ticket (since project files cannot be attached to forum posts). This will hopefully allow me to investigate further and better assist you. 

Regards,
Vladimir Stoyanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
DateTimePicker
Asked by
Lubch
Top achievements
Rank 1
Answers by
Lubch
Top achievements
Rank 1
George
Telerik team
Pana
Telerik team
Oleg
Top achievements
Rank 1
Kalin
Telerik team
Markus Stehle
Top achievements
Rank 1
Susmitha
Top achievements
Rank 1
Veteran
Iron
Vladimir Stoyanov
Telerik team
Share this question
or