【问题标题】:Windows Store App 8.1 Crashes. PRISMWindows 应用商店应用程序 8.1 崩溃。棱镜
【发布时间】:2014-02-12 03:52:53
【问题描述】:

我正在从“PRISM for windows runtime 8.1”创建一个新项目。每次我试图点击设置魅力时,应用程序都会崩溃。但是从 8.0 创建一个新项目不会使应用程序崩溃。有人知道如何解决这个问题吗?

我得到的错误是

Message = "System.NullReferenceException:对象引用未设置为 一个对象的实例。\r\n at Microsoft.Practices.Prism.StoreApps.MvvmAppBase.OnCommandsRequested(SettingsPane 发件人,SettingsPaneCommandsRequestedEventArgs args)"

编辑:这是崩溃时自动生成的文件。

namespace TestApp
{
#if !DISABLE_XAML_GENERATED_MAIN
    public static class Program
    {
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Windows.UI.Xaml.Build.Tasks"," 4.0.0.0")]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        static void Main(string[] args)
        {
            global::Windows.UI.Xaml.Application.Start((p) => new App());
        }
    }
#endif

    partial class App : global::Microsoft.Practices.Prism.StoreApps.MvvmAppBase
    {
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Windows.UI.Xaml.Build.Tasks"," 4.0.0.0")]
        private bool _contentLoaded;

        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Windows.UI.Xaml.Build.Tasks"," 4.0.0.0")]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public void InitializeComponent()
        {
            if (_contentLoaded)
                return;

            _contentLoaded = true;
#if DEBUG && !DISABLE_XAML_GENERATED_BINDING_DEBUG_OUTPUT
            DebugSettings.BindingFailed += (sender, args) =>
            {
                global::System.Diagnostics.Debug.WriteLine(args.Message);
            };
#endif
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
            UnhandledException += (sender, e) =>
            {
                if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break(); <---- the debugger stays on this line.
            };
#endif
        }
    }
}

【问题讨论】:

  • 能否请您证明您的相关代码引发了该异常?
  • @SonerGönül 我什至还没有开始编写任何代码。所有代码都来自模板。但是当尝试运行应用程序并单击设置魅力时,它会崩溃。

标签: c# windows-store-apps


【解决方案1】:

正如 ClevelandBuckeye 所指出的那样,Prism 代码中确实存在一个错误,它无法处理未配置任何设置的情况。

您不必修复它们的源代码,只需在您的 App 类中覆盖 GetSettingsCommands,并返回一个空的命令列表,如下所示:

protected override IList<SettingsCommand> GetSettingsCommands()
{
    return new List<SettingsCommand>();
}

如果您想查看如何完全实现此功能的示例,请查看 AdventureWorks 参考实现here

【讨论】:

  • 很抱歉我没有回答我自己的问题,但这就是我所做的。
【解决方案2】:

从项目站点下载开源项目。然后在 VS 中选择将现有项目添加到您的解决方案并添加 Prism for win rt。现在您可以编辑和修复错误。 在 MvvmAppBase.cs 中,第 284 行在此处添加一个空检查。

private void OnCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
    if (args == null || args.Request == null || args.Request.ApplicationCommands == null)
    {
        return;
    }

    var applicationCommands = args.Request.ApplicationCommands;
    var settingsCommands = GetSettingsCommands();
    if (settingsCommands == null) { return; }
    foreach (var settingsCommand in settingsCommands)
    {
        applicationCommands.Add(settingsCommand);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多