Invalid cast exception

25 posts, 0 answers
  1. Yordan
    Yordan avatar
    14 posts
    Member since:
    Jan 2013

    Posted 21 Apr 2015 Link to this post

    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

  2. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 22 Apr 2015 Link to this post

    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.

     
  3. DevCraft banner
  4. Mihail
    Mihail avatar
    6 posts
    Member since:
    Feb 2015

    Posted 23 Apr 2015 in reply to Ves Link to this post

    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

  5. Trevor Smith
    Trevor Smith avatar
    8 posts
    Member since:
    Oct 2009

    Posted 16 Aug 2015 in reply to Ves Link to this post

    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
  6. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 17 Aug 2015 Link to this post

    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
  7. Yordan
    Yordan avatar
    14 posts
    Member since:
    Jan 2013

    Posted 17 Aug 2015 in reply to Jack Link to this post

    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

  8. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 17 Aug 2015 Link to this post

    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
  9. Trevor Smith
    Trevor Smith avatar
    8 posts
    Member since:
    Oct 2009

    Posted 17 Aug 2015 Link to this post

    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
  10. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 20 Aug 2015 Link to this post

    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
  11. Trevor Smith
    Trevor Smith avatar
    8 posts
    Member since:
    Oct 2009

    Posted 20 Aug 2015 in reply to Pavel R. Pavlov Link to this post

    Its mentioned in the Calendar for Tamarin.Forms Styling 

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

  12. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 24 Aug 2015 Link to this post

    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
  13. Steve
    Steve avatar
    1 posts
    Member since:
    Nov 2015

    Posted 24 Nov 2015 Link to this post

    Was this original issue from April resolved?  

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

  14. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 27 Nov 2015 Link to this post

    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
  15. Blair
    Blair avatar
    22 posts
    Member since:
    Jun 2012

    Posted 06 Jul in reply to Pavel R. Pavlov Link to this post

    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.
  16. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 07 Jul Link to this post

    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
  17. Blair
    Blair avatar
    22 posts
    Member since:
    Jun 2012

    Posted 07 Jul in reply to Pavel R. Pavlov Link to this post

    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;
                
           }

  18. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 08 Jul Link to this post

    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
  19. Blair
    Blair avatar
    22 posts
    Member since:
    Jun 2012

    Posted 08 Jul in reply to Pavel R. Pavlov Link to this post

    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.

  20. Blair
    Blair avatar
    22 posts
    Member since:
    Jun 2012

    Posted 08 Jul Link to this post

    Sorry, the version is 2016.2.614
  21. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 13 Jul Link to this post

    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
  22. Chris
    Chris avatar
    3 posts
    Member since:
    Jan 2012

    Posted 31 Aug Link to this post

    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

  23. Chris
    Chris avatar
    3 posts
    Member since:
    Jan 2012

    Posted 31 Aug in reply to Chris Link to this post

    *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

  24. Vladislav
    Admin
    Vladislav avatar
    276 posts

    Posted 02 Sep Link to this post

    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
  25. James
    James avatar
    4 posts
    Member since:
    Jun 2016

    Posted 15 Sep in reply to Vladislav Link to this post

    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.

  26. Vladislav
    Admin
    Vladislav avatar
    276 posts

    Posted 19 Sep Link to this post

    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
Back to Top
DevCraft banner