System.TypeLoadException Could not find Windows Runtime type 'Windows.Foundation' exception

拥有回忆 提交于 2019-12-11 11:03:09

问题


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:

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:

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?

UPDATE
This is the Stack Trace

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#



And the content of my MainPage.xaml

<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}">

    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="2*" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid x:Name="myGrid" Grid.Row="0">
            <TextBlock x:Name="OutputText">
                    Output will appear here <LineBreak />
            </TextBlock>
        </Grid>

        <ScrollViewer Grid.Row="1" VerticalAlignment="Stretch">
            <Button Content="Do something" Click="Button_Click" HorizontalAlignment="Center" />
        </ScrollViewer>
    </Grid>
</Page>

来源:https://stackoverflow.com/questions/26213950/system-typeloadexception-could-not-find-windows-runtime-type-windows-foundation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!