InvalidCastException during navigation

YannBartelYannBartel USMember
edited November 2017 in Xamarin.iOS

I have a problem with the navigation of my iOS app developed using Xamarin.

On any single view in my app, when I used at least one time the back button and popped a view controller, I may have to deal with this System.InvalidCastException on my main class :

Unable to cast object of type 'App.iOS.UI.PhotoTaker.PhotoTakerViewController' (Objective-C type: 'WorkZoneSelectorViewController') to type 'App.iOS.UI.WorkZoneSelector.WorkZoneSelectorViewController'.
Additional information:
    Selector: viewDidLoad
    Method: App.iOS.UI.WorkZoneSelector.WorkZoneSelectorViewController:ViewDidLoad ()

In this example, I was on a PhotoTakerViewController and used a PopToRootViewController to go back succesfully to the HomeViewController (this can also happen when I use the "back" button until I'm back on the HomeViewController). Then I tried to use a segWorkZoneSelector to display a WorkZoneViewController. This is where this error appeared. So, for a reason I don't understand, the app try to cast the last view controller I have loaded to the view controller I want to display right now. PhotoTakerViewController and WorkZone inherits from a common AppViewController. None of these 3 classes have an ExportAttribute

I'm not able to reproduce this error systematically.

Something odd with this error message is also the fact that it says that the app crashed on the method WorkZoneSelectorViewController:ViewDidLoad. But when I try to add some instructions at the beginning of the method, these are never called.



  • pmlkpmlk Member

    I think I have the exact same issue. I have a navigation controller. The root view displays a table. Clicking on a row in one of two sections performs a segue (show) to a FooViewController, clicking on a row in the other section performs the same segue (show) to a BarViewController.

    Navigating back and forth between RootVC, FooVC, BarVC using the "< Root" button and by clicking on the respective table cells, works fine a couple of times. But then the InvalidCastException is thrown eventually.

    I am able to somewhat reproduce this error by alternating between FooVC and BarVC (going to Root in between, of course). I can usually go to FooVC and BarVC twice before it crashes on the third attempt.
    Another way is to go back and forth between RootVC and FooVC (or BarVC) about three times, then trying to navigate to BarVC (or FooVC, respectively).

Sign In or Register to comment.