[iOS] NavigationPage InvalidCastException
See original GitHub issueDescription
I deploy an iOS app and it appears to navigate but after a second (likely due to the debugger being slow) I break at Main with an InvalidCastException
and no extra details.
Steps to Reproduce
Create a new Maui App from the template.
Go to App.Xaml.cs
and replace the Shell with
MainPage = new NavigationPage(new Page() { BackgroundColor = Colors.Lavender });
Link to public reproduction project repository
It is in the template
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
Tested on iOS 16
Did you find any workaround?
No response
Relevant log output
at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].get_VirtualView()
at Microsoft.Maui.Handlers.PageHandler.CreatePlatformView()
at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnCreatePlatformView()
at Microsoft.Maui.Handlers.ViewHandler.OnCreatePlatformElement()
at Microsoft.Maui.Handlers.ElementHandler.CreatePlatformElement()
at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view)
at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IView view)
at Microsoft.Maui.Handlers.ContentViewHandler.SetVirtualView(IView view)
at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view)
at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value)
at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value)
at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context)
at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context)
at Microsoft.Maui.Controls.Handlers.Compatibility.NavigationRenderer.CreateViewControllerForPage(Page page)
at Microsoft.Maui.Controls.Handlers.Compatibility.NavigationRenderer.OnPushAsync(Page page, Boolean animated)
at Microsoft.Maui.Controls.Handlers.Compatibility.NavigationRenderer.<ViewDidLoad>b__50_0(Page p)
at ObjCRuntime.Runtime.ThrowException(IntPtr gchandle)
at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName)
at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass)
at MauiApp1.Program.Main(String[] args) in C:\Repositories\MauiApp1\MauiApp1\Platforms\iOS\Program.cs:line 13
Issue Analytics
- State:
- Created 9 months ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Xamarin iOS. InvalidCastException during navigation
I have a problem with the navigation of my iOS app developed using Xamarin. On any single view in my app, when I...
Read more >InvalidCastException using FlyoutPage - Microsoft Q&A
It works when I set my FlyoutPage as the entry point of my application, but when I'm trying to access it using the...
Read more >Specified cast is not valid. Xamarin.Forms
Hi Everyone ! i have this project in which i need to Retrieve a list of data, when i click the Retrieve Button,...
Read more >[Code]-Xamarin.iOS randomly crashes invalid cast exception
Something like this: public class TableViewController : UITableViewController { public TableViewController () : base (UITableViewStyle.Grouped) { this.
Read more >Xamarin Community Forums
InvalidCastException : Specified cast is not valid. at (wrapper castclass) System. ... iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Michal-MK On this line change
Page
toContentPage
Verified this on Visual Studio Enterprise 17.7.0 Preview 1.0. Repro on iOS 16.4 with below Project: 12208.zip