BlankPage constructor cannot initialize components

This happens when you change a namespace for a class, you must do the same inside the XAML file.

There are two places inside the XAML file with the old namespace.


For me, the project was inside solution with other projects. When suggestions here did not work, a simple unloading and reloading the project from solution did the trick and fix all errors (with rebuilding of course).


Just to give a bit more information on how to fix this (since this explanation is a bit on the vague side)..

This issue (for me) was caused because I changed the namespace in the code after I created the project. In order to fix this issue I had to make some changes in a couple of locations:

1: In App.xaml I had to change the following:

<Application
  x:Class="New.Namespace.App"

2: In MainPage.xaml I had to change the following:

<Page
  x:Class="New.Namespace.MainPage"

You will also want to make sure that you change the 'namespace' line in your App.xaml.cs as well as your MainPage.xaml.cs.

Finally, you will also want to make sure you update the Project Entrypoint in the Package.appxmanifest to point to "New.Namespace.App".


If your Main class's namespace is different than .xaml file's x:Class attribute, you will get this error. For instance;

Your MainPage.xaml.cs;

    namespace UWPControls
    {
        /// <summary>
        /// An empty page that can be used on its own or navigated to within a Frame.
        /// </summary>
        public sealed partial class MainPage : Page
        {
            public MainPage()
            {
                this.InitializeComponent();
            }
        }
    }

Your MainPage.xaml;

<Page
    x:Class="UWPControls_Different.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:UWPHelloWorld"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
</page>

You're going to see the error until changing x:class to the;

x:Class="UWPControls.MainPage"