C# System.TypeLoadException找不到Windows运行时类型';Windows.Foundation';例外
在我的WindowsPhone8.1应用程序中,我创建了一个自定义页面,然后导航到它,所有这些都是代码隐藏的。我的CustomPage类是:C# System.TypeLoadException找不到Windows运行时类型';Windows.Foundation';例外,c#,xaml,windows-runtime,windows-store-apps,windows-phone-8.1,C#,Xaml,Windows Runtime,Windows Store Apps,Windows Phone 8.1,在我的WindowsPhone8.1应用程序中,我创建了一个自定义页面,然后导航到它,所有这些都是代码隐藏的。我的CustomPage类是: using Windows.UI.Xaml.Controls; namespace TestApp { public class CustomPage : Page { public CustomPage() { this.BuildPage(); } private vo
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;
}
}
}
然后在我的MainPage.xaml.cs
中,我正在这样做:
CustomPage myNewPage = new CustomPage();
Frame.Navigate(myNewPage.GetType());
但是,这会引发System.TypeLoadException异常-找不到Windows运行时类型“Windows.Foundation”
如果我不做一个CustomPage类,只做一个Page类,它工作得很好,但是我需要创建一个CustomPage类,我如何解决这个问题呢?更新
这是堆栈跟踪
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#
以及我的主页的内容。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>
输出将显示在此处
请向我们展示您的XAML。没有XAML,我完全是用代码创建页面的。事实上,您有MainPage.XAML.cs
显然让人觉得有一些XAML。你真的没有这个XAML文件吗?请包含堆栈跟踪,以便我们看到它失败的地方?MainPage.xaml确实是一个xaml页面,但是它的内容与本例无关,因为除了默认设置之外,我没有其他内容。我会在一秒钟内将堆栈添加到文章中。无论如何,我都会包括XAML-直到你知道什么是错误的,很难知道什么是不相关的。。。