This is a migrated thread and some comments may be shown as answers.
Invalid cast exception
24 Answers 73 Views
This is a migrated thread and some comments may be shown as answers.
Yordan
Top achievements
Rank 1
Yordan asked on 21 Apr 2015, 09:04 AM

Hello,

I am  getting the following exception, when I use the Calendar control in Year view mode. (The same also happens when the calendar is in week mode)

2015-04-21 11:57:37.212 DzjinTonikMobileiOS[706:165460] Unhandled managed exception: Unable to cast object of type 'TelerikUI.TKCalendarYearPresenter' to type 'UIKit.UIView' (System.InvalidCastException)
  at ObjCRuntime.Runtime.GetNSObject[UIView] (IntPtr ptr) [0x00000] in <filename unknown>:0 
  at UIKit.UIView.get_Superview () [0x00010] in /Developer/MonoTouch/Source/monotouch/src/build/native/UIKit/UIView.g.cs:3239 
  at Xamarin.Forms.Platform.iOS.PageRenderer+<ViewAndSuperviewsOfView>d__0.MoveNext () [0x00000] in <filename unknown>:0 
  at System.Linq.Enumerable.Any[UIView] (IEnumerable`1 source, System.Func`2 predicate) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.PageRenderer.OnShouldReceiveTouch (UIKit.UIGestureRecognizer recognizer, UIKit.UITouch touch) [0x00000] in <filename unknown>:0 
  at UIKit.UIGestureRecognizer+_UIGestureRecognizerDelegate.ShouldReceiveTouch (UIKit.UIGestureRecognizer recognizer, UIKit.UITouch touch) [0x0000d] in /Developer/MonoTouch/Source/monotouch/src/
build/native/UIKit/UIGestureRecognizer.g.cs:625 
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0001c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:45 
  at DzjinTonikMobile.iOS.Application.Main (System.String[] args) [0x00001] in d:\iBoris\DzjinTonikMobile\Main\DzjinTonikMobile\DzjinTonikMobile.iOS\Main.cs:12 

My details:
OS: Windows 8.1
Regional settings: bg-BG
IDE: Visual studio Premium 2013 version 12.0.31101.00 update 4
Xamarin  SDK: 3.9.547.0
Xamarin.iOS   8.9.1.0
Telerik for Xamarin version: 2015.1.319

Regards,
Mihail

24 Answers, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 22 Apr 2015, 03:51 PM
Hi Mihail,

Are you able to reproduce the issue consistently? We were able to reproduce it, but it seems to happen intermittently. To make it more complex, the stack trace does not contain code from Telerik and the only clue we have at the moment is that the framework tries to handle TKCalendarYearPresenter as UIView. We will continue to look into the problem and we'll get back to you when we have more info.

Best regards,
Ves
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Mihail
Top achievements
Rank 1
answered on 23 Apr 2015, 12:13 PM

Ves,

Thank you for the fast reply. 

Yes, this problem occurs every time when I try to click on some month (when in year mode) or when I click on a certain day (when in week mode).
I am looking forward to future release that will fix this unfortunate problem.

Regards,
Mihail

0
Trevor Smith
Top achievements
Rank 1
answered on 16 Aug 2015, 12:15 PM
I get the same thing  ... System.InvalidCastException: Unable to cast object of type 'TelerikUI.TKCalendarMonthPresenter' to type 'UIKit.UIView'....   but only when debugging on my Iphone .... ie not in the emulator that works as expected
0
Jack
Telerik team
answered on 17 Aug 2015, 01:27 PM
Hi Trevor,

We located the issue and it will be addressed with our upcoming release later this month. I added the issue in our feedback portal where you can track its status. I updated also your Telerik points for reporting it.

Should you have any additional questions, do not hesitate to ask.

Regards,
Jack
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
Yordan
Top achievements
Rank 1
answered on 17 Aug 2015, 01:34 PM

Jack,

If you look up you will see that I reported the issue, not Trevor. Actually, at the time that I posted this, I was able to reproduce the bug also in the simulator.
Nevertheless, I am glad that a fix will come in the next release.

Regards,
Pavel

0
Jack
Telerik team
answered on 17 Aug 2015, 01:43 PM
Hi Pavel,

Thank you for pointing this out. Yes, I confirm that the issue occurs both when using a simulator and on device. I updated your points accordingly.

Regards,
Jack
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
Trevor Smith
Top achievements
Rank 1
answered on 17 Aug 2015, 06:58 PM
There is another problem with the calendar.   The SelectedDate is not updated until after the EvaluateCellStyle method completes.  This means that when you use the SelectedDate in the EvaluateCellStyle method it is still the previously selected date and not the new selected date
0
Pavel R. Pavlov
Telerik team
answered on 20 Aug 2015, 12:50 PM
Hi Trevor, 

It seems that there is no EvaluateCellStyle method in our UI for iOS, UI for Android or UI for Xamarin suites of controls. Where do you find it? Where it is defined? 

Please elaborate more on your scenario.

Regards,
Pavel R. Pavlov
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
Trevor Smith
Top achievements
Rank 1
answered on 20 Aug 2015, 03:37 PM

Its mentioned in the Calendar for Tamarin.Forms Styling 

http://docs.telerik.com/devtools/xamarin/controls/calendar/features/calendar-styling

0
Pavel R. Pavlov
Telerik team
answered on 24 Aug 2015, 06:45 AM
Hi Trevor,

The confusion comes from the fact that "EvaluateCellStyle" is the name of a custom method used for demonstration purposes in the referenced article. It is not part of our control.

Anyway, I got your point. Let me try to explain what is happening on your side. I would like to turn your attention to the fact that the article demonstrates how the RadCalendar.SetStyleForCell property can be used. Note that users are able to determine the type of the cell. There are three types of cells in the RadCalendar:
  1. Date - this is the type of all dates in a month.
  2. WeekNumber - if visualized these are the cells displaying which number is the visualized week.
  3. DayName - this is the row displaying the name of the days (e.g. Monday, Tuesday, Wednesday...)

This property should be used for customizing the mentioned aspects only. If you need to customize how the separate dates look like you need to change your approach.

For example you can check if the cell that comes in the custom method is of type DayName or WeekNumber. If so you can return the appropriate CalendarCellStyle. If the cell is neither of them you can determine what exactly the cell will be used for based on the properties of the cell itself. You can cast it to CalendarDayCell and then check its properties. You can use the following code to start the required customization:

private CalendarCellStyle SetStyleForCell(CalendarCell cell)
{
    if (cell.Type == CalendarCellType.DayName)
    {
        return new CalendarCellStyle
        {
            BackgroundColor = Color.Transparent,
            BorderColor = Color.Silver,
            BorderThickness = CalendarCustomResources.Instance.BorderThickness,
            FontSize = CalendarCustomResources.Instance.DayNamesFontSize,
            FontWeight = FontWeight.Bold,
            ForegroundColor = Color.FromRgb(0, 122, 255)
        };
    }
 
    if (cell.Type == CalendarCellType.WeekNumber)
    {
        return new CalendarCellStyle
        {
            BackgroundColor = CalendarCustomResources.Instance.Background,
            BorderColor = Color.Silver,
            BorderThickness = CalendarCustomResources.Instance.BorderThickness,
            FontSize = CalendarCustomResources.Instance.WeekNumbersFontSize,
            FontWeight = FontWeight.Normal,
            ForegroundColor = Color.Silver
        };
    }
 
    var defaultStyle = new CalendarCellStyle
    {
        BackgroundColor = CalendarCustomResources.Instance.Background,
        BorderColor = Color.Silver,
        BorderThickness = CalendarCustomResources.Instance.BorderThickness,
        FontSize = CalendarCustomResources.Instance.FontSize,
        FontWeight = FontWeight.Normal,
        ForegroundColor = Color.FromRgb(139, 209, 0)
    };
 
    var dayCell = cell as CalendarDayCell;
 
    if (dayCell != null)
    {
        if (dayCell.IsFromCurrentMonth)
        {
            if (dayCell.IsToday)
            {
                defaultStyle.ForegroundColor = Color.FromRgb(0, 122, 255);
                defaultStyle.FontWeight = FontWeight.Bold;
            }
        }
        else
        {
            if (dayCell.IsToday)
            {
                defaultStyle.ForegroundColor = Color.FromRgb(115, 174, 239);
            }
            else
            {
                defaultStyle.ForegroundColor = Color.FromRgb(166, 181, 137);//212, 251, 133);
            }
        }
 
        if (dayCell.IsSelected)
        {
            defaultStyle.ForegroundColor = CalendarCustomResources.Instance.SelectedCellForegroundColor;
        }
 
        return defaultStyle;
    }
I hope this will get you started. Please do not hesitate to contact us if you need any further assistance.

Regards,
Pavel R. Pavlov
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
Steve
Top achievements
Rank 1
answered on 24 Nov 2015, 07:47 PM

Was this original issue from April resolved?  

I am also encountering this when I zoom out to the month view then select a month.  

0
Pavel R. Pavlov
Telerik team
answered on 27 Nov 2015, 07:43 AM
Hi Steve,

We will release our latest version of the components by the end of the workday today. You will be able to check if your issue is properly addressed and fixed. If however the issue still exist, please contact us with some additional details on that matter.

Regards,
Pavel R. Pavlov
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
Blair
Top achievements
Rank 1
answered on 06 Jul 2016, 01:43 PM
I know this is an old post, but has this been fixed? I just experienced it. It seems to only happen when in "Release" configuration and when published. In debug I don't get the problem.
0
Pavel R. Pavlov
Telerik team
answered on 07 Jul 2016, 06:03 AM
Hello Blair,

Could you please share with us a sample project demonstrating the reported issue? It will help us to investigate the reasons behind. Also it will be nice to share exact steps that reproduce the behavior on your side. 

We are looking forward to hearing from you.

Regards,
Pavel R. Pavlov
Telerik by Progress
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
Blair
Top achievements
Rank 1
answered on 07 Jul 2016, 02:23 PM

Hey Pavel,

Well, let me pose this question first and this might solve the problem.

It appears that in iOS that if the CalendarViewMode is Year and I select a month, RadCalendar does not automatically go to that month like Android does. Is this a known issue or am I missing something? My only solution to this problem was to do the following:

private void InitCalendar(CalendarViewMode mode)
       {
           ViewMode = mode;
           calendar = new RadCalendar()
                   {
                       HorizontalOptions = LayoutOptions.FillAndExpand,
                       VerticalOptions = LayoutOptions.FillAndExpand,
 
                   };
 
           calendar.ViewChanged += calendar_ViewChanged;
 
           calendar.SelectionChanged += (sender, args) =>
           {
                
               if (calendar.ViewMode == CalendarViewMode.Year)
               {
                    InitCalendar(CalendarViewMode.Month);
                    
               }
 
           };
 
           calendar.NativeControlLoaded += (sender, arg) =>
           {
               (sender as RadCalendar).TrySetViewMode( ViewMode);
           };
 
           calendar.SetStyleForCell = EvaluateCellStyle;
 
           Content = calendar;
            
       }

0
Pavel R. Pavlov
Telerik team
answered on 08 Jul 2016, 06:52 AM
Hi Blair,

I tested the reported steps and could not see the behavior that you observe. Could you please share with us the version of our components that you use? This may be a difference that matters in this scenario.

Regards,
Pavel R. Pavlov
Telerik by Progress
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
Blair
Top achievements
Rank 1
answered on 08 Jul 2016, 11:07 AM

Pavel,

Just a reminder, you have to build using "Release" configuration. The version is 2016.6.614. 

Also, are you saying that in iOS "Year" view mode, when you select a month that it should automatically switch to the Month view like Android?

Thanks.

0
Blair
Top achievements
Rank 1
answered on 08 Jul 2016, 11:20 AM
Sorry, the version is 2016.2.614
0
Pavel R. Pavlov
Telerik team
answered on 13 Jul 2016, 08:11 AM
Hello Blair,

Please accept our apology for misleading you. It is true that in Year ViewMode the iOS RadCalendar does not navigate to the specific month after tap. You should set the ViewMode to MonthNames in order to achieve the behavior that you need.

Please give this approach a try and let us know if you need any further assistance.

Regards,
Pavel R. Pavlov
Telerik by Progress
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
Chris
Top achievements
Rank 1
answered on 31 Aug 2016, 10:14 AM

Hello Pavel,

I think the bug still exist because we also encountered it but can only reproduce it reliable when deploying it on a real device. What we try to do is displaying the RadCalendar initially in CalendarViewMode 'Month'. After loading the user has the opportunity to select CalendarViewMode 'Year'. After the Calendar has switched the viewMode the user taps/touches on a month and the app crashes with the following exception in the VisualStudio Output Window:

System.InvalidCastException: Unable to cast object of type 'TelerikUI.TKCalendarYearPresenter' to type 'UIKit.UIView'
  at ObjCRuntime.Runtime.GetNSObject[T] (IntPtr ptr) <0x108a03c + 0x00278> in <filename unknown>:0
  at UIKit.UIView.get_Superview () [0x00010] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/src/build/ios/native/UIKit/UIView.g.cs:3648
  at Xamarin.Forms.Platform.iOS.PageRenderer+<ViewAndSuperviewsOfView>d__34.MoveNext () [0x00035] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:223
  at Xamarin.Forms.Platform.iOS.PageRenderer.OnShouldReceiveTouch (UIKit.UIGestureRecognizer recognizer, UIKit.UITouch touch) [0x00037] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:189
  at UIKit.UIGestureRecognizer+_UIGestureRecognizerDelegate.ShouldReceiveTouch (UIKit.UIGestureRecognizer recognizer, UIKit.UITouch touch) [0x0000d] in /Users/builder/data/lanes/3539/f3744
4ae/source/maccore/src/build/ios/native/UIKit/UIGestureRecognizer.g.cs:819
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/src/UIKit/UIApplication.cs:79
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0001c] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/src/UIKit/UIApplication.cs:62
  at Mobile.Forms.View.iOS.Application.Main (System.String[] args) [0x00002] in D:\XXX\YYY\proj\dev\dev\src\Mobile\Forms\View\View.iOS\Main.cs:16
The app has been terminated.

The app crashes without having any chance to catch an event from RadCalendar like 'ViewChanged', 'SelectionChanged' nor 'DisplayDateChanged'.

Details:

Tested on iPhone 5 and iPad 2

Telerik UI for Xamarin: latest stable nuget version 2016.3.830.1

Xamarin.Forms Version 2.3.1.114

Visual Studio 2015 Enterprise Update 3

Region Settings: 'de-DE'

 

Thanks in advance

Chris

0
Chris
Top achievements
Rank 1
answered on 31 Aug 2016, 12:14 PM

*UPDATE*

I just encountered a strange behavior. The described behavior only occurs when the device is connected (via usb) to the mac. When it's not plugged in and I start our debug compiled app it doesn't crash.

Maybe this will help a little bit

Regards

Chris

0
Vladislav
Telerik team
answered on 02 Sep 2016, 12:43 PM
Hi Chris,

Thank you for this report.
We confirm that this is actually a bug in the RadCalendar control and we will do our best to provide a fix for it in some of our future releases.

Your Telerik points are updated accordingly.

Regards,
Vladislav
Telerik by Progress
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
James
Top achievements
Rank 1
answered on 15 Sep 2016, 04:06 PM

Hi, I have just encountered this bug, it seems my app throws the invalid cast exception only on my iphone 6, not in the simulator at all. It throws it in release and debug with and without the usb cable attached. Is there a bug report for this one so I can follow its progress? It is seriously hindering our development efforts.

 

Thanks, James.

0
Vladislav
Telerik team
answered on 19 Sep 2016, 08:45 AM
Hi James,

Thank you for contacting us.
We confirm that this issue is more general than it's original description in this thread.
It is already logged and I just made it visible here where you can track it's progress.

Regards,
Vladislav
Telerik by Progress
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
Asked by
Yordan
Top achievements
Rank 1
Answers by
Ves
Telerik team
Mihail
Top achievements
Rank 1
Trevor Smith
Top achievements
Rank 1
Jack
Telerik team
Yordan
Top achievements
Rank 1
Pavel R. Pavlov
Telerik team
Steve
Top achievements
Rank 1
Blair
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Vladislav
Telerik team
James
Top achievements
Rank 1
Share this question
or