.NET MAUI – How to fix “Either set MainPage or override CreateWindows.”

January 17, 2022

I was getting an error in my MAUI app where you run your app, go back to Home screen and re-run the app again, it throws System.NoImplementedException: “Either set MainPage or override CreateWindow”.

Sounds like the app doesn’t happy with its lifecycle. Then, I found this article on Microsoft to get familiar on MAUI app’s lifecycle.

As the error message states, the solution was to implement CreateWindow method that overrides Windows class’ method. Add below code in App.xaml.cs just below public App() constructor.

protected override Window CreateWindow(IActivationState activationState)
{
	MainPage = new MainPage();
	return base.CreateWindow(activationState);
}