this is really throwing me for a loop. I installed Xamarin for Visual Studio, created an empty project and connected to my Mac. I simulate an iPhone and get this error
Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Application windows are expected to have a root view controller at the end of application launch
Which is being caused by the call to UIApplication.Main in the Main.cs
class
using UIKit;
namespace testapp
{
public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, "AppDelegate");
}
}
}
I have absolutely nowhere to think to look - has anyone run into this before?
I faced the same error and what was wrong in my case is that I run async/await methods before MainPage was set. So, I just moved MainPage = new MainPage(); right after InitializeComponent(); and it works now.
It seams that AppDelegate
is not implemented correctly in your project. iOS needs to know what´s the root controller (UIViewController) to init the app. The AppDelegate
class is responsible for setting it. This will add an empty view controller at the app initialization:
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
UIWindow window;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
window.RootViewController = new UIViewController ();
window.MakeKeyAndVisible ();
return true;
}
}
I had the same problem recently when importing an existing project.
Setting the MainPage
in App.cs
fixed it for me along with the changes mentioned for AppDelegate
by xleon
MainPage = new ContentPage();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With