In my Windows Phone 8.1 app I'm creating a CustomPage and then navigating to it, all in code behind. My CustomPage class is:

C#
using Windows.UI.Xaml.Controls;
namespace TestApp {
        public class CustomPage : Page {
                public CustomPage() {
                        this.BuildPage();
                }
                private void BuildPage() {
                        var panel = new StackPanel();
                        panel.Children.Add(new TextBlock { Text = "Hello World" });
                        this.Content = panel;
                }
        }
}

And then in my MainPage.xaml.cs I'm doing this:

Code
CustomPage myNewPage = new CustomPage(); Frame.Navigate(myNewPage.GetType());

However this throws a System.TypeLoadException exception - Could not find Windows Runtime type 'Windows.Foundation'

If I don't do a CustomPage class just a Page class, it works fine, but I need to create a CustomPage class, how could I solve this?