title: System.TypeLoadException Could not find Windows Runtime type 'Windows.Foundation' exception
body: <p>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:</p>
  
  <pre><code>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;
          }
      }
  }
  </code></pre>
  
  <p>And then in my <code>MainPage.xaml.cs</code> I'm doing this:</p>
  
  <pre><code>CustomPage myNewPage = new CustomPage();
  Frame.Navigate(myNewPage.GetType());
  </code></pre>
  
  <p>However this throws a System.TypeLoadException exception - <code>Could not find Windows Runtime type 'Windows.Foundation'</code>
  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?<br><br></p>
  
  <p><b>UPDATE</b><br>
  This is the Stack Trace</p>
  
  <pre><code>MyCustomClass.DLL!HelpingTool.NavigateToNewPage() Line 50   C#
  MyCustomClass.DLL!HelpingTool.InitializeToolset() Line 23   C#
  MyCustomClass.DLL!HelpingTool.HelpingTool(Windows.UI.Xaml.Controls.Page mainPage = {TestApp.MainPage}) Line 18  C#
  TestApp.exe!TestApp.MainPage.Button_Click(object sender = {Windows.UI.Xaml.Controls.Button}, Windows.UI.Xaml.RoutedEventArgs e = {Windows.UI.Xaml.RoutedEventArgs}) Line 88 C#
  </code></pre>
  
  <p><br><br>
  And the content of my MainPage.xaml<br></p>
  
  <pre><code>&lt;Page
      x:Class="TestApp.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="using:TestApp"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      Loaded="Page_Loaded"
      mc:Ignorable="d"
      Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"&gt;
  
      &lt;Grid x:Name="LayoutRoot"&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="2*" /&gt;
              &lt;RowDefinition Height="*" /&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;Grid x:Name="myGrid" Grid.Row="0"&gt;
              &lt;TextBlock x:Name="OutputText"&gt;
                      Output will appear here &lt;LineBreak /&gt;
              &lt;/TextBlock&gt;
          &lt;/Grid&gt;
  
          &lt;ScrollViewer Grid.Row="1" VerticalAlignment="Stretch"&gt;
              &lt;Button Content="Do something" Click="Button_Click" HorizontalAlignment="Center" /&gt;
          &lt;/ScrollViewer&gt;
      &lt;/Grid&gt;
  &lt;/Page&gt;
  </code></pre>