在Windows Phone 8中,我不断收到System.Windows.Markup.XamlParseException错误

3
我收到的错误信息是:

在 System.Windows.ni.dll 中发生了类型为 'System.Windows.Markup.XamlParseException' 的第一次机会异常

调用堆栈追溯回到这段代码。

 public MainPage()
        {
            **InitializeComponent();**
            this.Init();

            // Set the data context of the listbox control to the sample data
            DataContext = App.ViewModel;
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);


        }

还有在InitializeComponent()行上的错误。

public void InitializeComponent() {
        if (_contentLoaded) {
            return;
        }
        _contentLoaded = true;
        System.Windows.Application.LoadComponent(this, new System.Uri("/App;component/MainPage.xaml", System.UriKind.Relative));
        this.LayoutRoot = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
        this.SSIDTextBox = ((System.Windows.Controls.TextBox)(this.FindName("SSIDTextBox")));
        this.PasswordTextBox = ((System.Windows.Controls.TextBox)(this.FindName("PasswordTextBox")));
        this.Auth_ListPicker = ((Microsoft.Phone.Controls.ListPicker)(this.FindName("Auth_ListPicker")));
        this.SaveButton = ((System.Windows.Controls.Button)(this.FindName("SaveButton")));
        this.GenerateButton = ((System.Windows.Controls.Button)(this.FindName("GenerateButton")));
        this.QRImage = ((System.Windows.Controls.Image)(this.FindName("QRImage")));
        this.Profiles= ((System.Windows.Controls.ListBox)(this.FindName("Profiles")));
    }
}

在我将WP 7.1转换为WP8之前,我没有遇到这个异常。

任何帮助都将不胜感激。

更新: 我添加了整个异常消息,这有助于确定问题吗?

'TaskHost.exe'(CLR C:\ windows \ system32 \ coreclr.dll:DefaultDomain):已加载'C:\ windows \ system32 \ mscorlib.ni.dll'。跳过加载符号。模块已优化,调试器选项“仅我的代码”已启用。 'TaskHost.exe'(CLR C:\ windows \ system32 \ coreclr.dll:Silverlight AppDomain):已加载'C:\ windows \ system32 \ System.Windows.RuntimeHost.ni.dll'。跳过加载符号。模块已优化,调试器选项“仅我的代码”已启用。 'TaskHost.exe'(CLR C:\ windows \ system32 \ coreclr.dll:Silverlight AppDomain):已加载'C:\ windows \ system32 \ System.Windows.ni.dll'。跳过加载符号。模块已优化,调试器选项“仅我的代码”已启用。 'TaskHost.exe'(CLR C:\ windows \ system32 \ coreclr.dll:Silverlight AppDomain):已加载'C:\ windows \ system32 \ System.Net.ni.dll'。跳过加载符号。模块已优化,调试器选项“仅我的代码”已启用。 'TaskHost.exe'(CLR C:\ windows \ system32 \ coreclr.dll:Silverlight AppDomain):已加载'C:\ windows \ system32 \ System.ni.dll'。跳过加载符号。模块已优化,调试器选项“仅我的代码”已启用。 'TaskHost.exe'(CLR C:\ windows \ system32 \ coreclr.dll:Silverlight AppDomain):已加载'C:\ windows \ system32 \ System.Xml.ni.dll'。跳过加载符号。模块已优化,调试器选项“仅我的代码”已启用。 'TaskHost.exe'(CLR C:\ windows \ system32 \ coreclr.dll:Silverlight AppDomain):已加载'C:\ Data \ Programs {64003C1B-A4FD-41FF-A132-2B6C9FE8EDC9} \ Install \ WifiQR.DLL'。已加载符号。 'TaskHost.exe'(CLR C:\ windows \ system32 \ coreclr.dll:Silverlight AppDomain):已加载'C:\ windows \ system32 \ Microsoft.Phone.ni.dll'。跳过加载符号。模块已优化,调试器选项“仅我的代码”已启用。 'TaskHost.exe'(CLR C:\ windows \ system32 \ coreclr.dll:Silverlight AppDomain):已加载'C:\ windows \ system32 \ Microsoft.Phone.Interop.ni.dll'。跳过加载符号。模块已优化,调试器选项“仅我的代码”已启用。 'TaskHost.exe'(CLR C:\ windows \ system32 \ coreclr.dll:Silverlight AppDomain):已加载'C:\ Data \ Programs {64003C1B-A4FD-41FF-A132-2B6C9FE8EDC9} \ Install \ Microsoft.Phone.Controls.Toolkit.DLL'。找不到或打开PDB文件。 'TaskHost.exe'(CLR C:\ windows \ system32 \ coreclr.dll:Silverlight AppDomain):已加载'C:\ Data \ Programs {64003C1B-A4FD-41FF-A132-2B6C9FE8EDC9} \ Install \ microsoft.phone.controls.DLL'。找不到或打开PDB文件。 'TaskHost.exe'(CLR C:\ windows \ system32 \ coreclr.dll:Silverlight AppDomain):已加载'C:\ windows \ system32 \ System.Core.ni.dll'。跳过加载符号。模块已优化,调试器选项“仅我的代码”已启用。 在System.Windows.ni.dll中发生了类型为'System.Windows.Markup.XamlParseException'的第一个机会异常

异常中没有更多的信息吗?消息部分说了什么?我记得类似的问题很难修复,但是通常会提供比你提供的更多的信息。 - Jon Skeet
1
很难猜测出问题所在。尝试删除你的XAML页面的部分内容,直到它开始工作,或者尝试向我们显示内部异常中的消息。 - Martin Suchan
我包含了整个输出。这有助于确定问题吗?我还尝试删除XAML页面的某些部分,但仍会抛出异常。 - Davy Li
发现问题了!我使用了以下步骤: 可以通过以下方式获取有关异常的更多信息:调试->异常 点击添加并键入“System.Windows.Markup.XamlParseException”,然后选择公共语言运行时异常 再次运行以找到引发异常的确切原因。 - Davy Li
@DavyLi,你也可以回答自己的问题,在Stackoverflow.com上这实际上是鼓励的。 - Prof. Falken
4个回答

11

只需在您的清单文件中添加权限。

  1. 前往WMAppmanifest.xml
  2. 选择“Capabalities”选项卡
  3. 现在勾选“ID_CAP_MAP”

8

发现问题!

  1. 调试->异常
  2. 点击添加并输入 "System.Windows.Markup.XamlParseException",选择公共语言运行时异常
  3. 再次运行程序,异常将会指出引起错误的确切行数。

原来只是一个简单的拼写错误。


0

我曾经遇到过类似的问题,后来发现重新添加点击事件就解决了。

这个问题出现在我从另一个XAML页面复制代码时。


0

在VS Express中使用Strg+Alt+F7可以帮助解决WP8更新后的问题。


4
你能否在回答中添加一些细节,例如该组合键的作用。如果微软在以后的Visual Studio版本中更改了该组合键,则此答案将无法帮助其他用户。 - BMac
如果Windows Phone想要被认真看作是一个开发平台,那么它的现状非常令人失望。 - Stephen Tetreault

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接