C# Windows应用商店应用程序8.1崩溃。棱镜
我正在从“PRISM for windows runtime 8.1”创建一个新项目。每次我试图点击设置时,应用程序就会崩溃。但是从8.0创建一个新项目并不会使应用程序崩溃。有人知道怎么解决这个问题吗 我得到的错误是 Message=“System.NullReferenceException:对象引用未设置为 对象的实例。\r\n位于 Microsoft.Practices.Prism.StoreApps.MvvmAppBase.OnCommandsRequested(设置span 发件人,设置spaneCommandSRequestedeventargs args)” 编辑:这是崩溃时自动生成的文件C# Windows应用商店应用程序8.1崩溃。棱镜,c#,windows-store-apps,C#,Windows Store Apps,我正在从“PRISM for windows runtime 8.1”创建一个新项目。每次我试图点击设置时,应用程序就会崩溃。但是从8.0创建一个新项目并不会使应用程序崩溃。有人知道怎么解决这个问题吗 我得到的错误是 Message=“System.NullReferenceException:对象引用未设置为 对象的实例。\r\n位于 Microsoft.Practices.Prism.StoreApps.MvvmAppBase.OnCommandsRequested(设置span 发件人,设
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
}
}
}
namespace TestApp
{
#如果!禁用\u XAML\u生成的\u MAIN
公共静态类程序
{
[全局::System.CodeDom.Compiler.GeneratedCodeAttribute(“Microsoft.Windows.UI.Xaml.Build.Tasks”,“4.0.0.0”)]
[全局::System.Diagnostics.DebuggerNonUserCodeAttribute()]
静态void Main(字符串[]参数)
{
全局::Windows.UI.Xaml.Application.Start((p)=>newapp());
}
}
#恩迪夫
分部类应用程序:全局::Microsoft.Practices.Prism.StoreApps.MvvmAppBase
{
[全局::System.CodeDom.Compiler.GeneratedCodeAttribute(“Microsoft.Windows.UI.Xaml.Build.Tasks”,“4.0.0.0”)]
私有bool_内容加载;
[全局::System.CodeDom.Compiler.GeneratedCodeAttribute(“Microsoft.Windows.UI.Xaml.Build.Tasks”,“4.0.0.0”)]
[全局::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public void InitializeComponent()
{
如果(_contentLoaded)
返回;
_contentLoaded=true;
#如果调试&&!禁用\u XAML\u生成的\u绑定\u调试\u输出
DebugSettings.BindingFailed+=(发送方,参数)=>
{
全局::System.Diagnostics.Debug.WriteLine(args.Message);
};
#恩迪夫
#如果调试&&!禁用\u XAML\u生成的\u中断\u未处理的\u异常
未处理的异常+=(发送方,e)=>
{
如果(global::System.Diagnostics.Debugger.IsAttached)global::System.Diagnostics.Debugger.Break();从项目站点下载开源项目。然后在VS中选择将现有项目添加到解决方案中,并为win rt添加Prism。现在,您可以编辑并修复该错误。
在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);
}
}
正如ClevelandBuckeye所指出的,Prism代码中确实存在一个bug,它无法处理未配置任何设置的情况
不过,您不必修复它们的源代码,只需覆盖应用程序类中的GetSettingsCommand,并返回一个空的命令列表,如下所示:
protected override IList<SettingsCommand> GetSettingsCommands()
{
return new List<SettingsCommand>();
}
受保护的覆盖IList GetSettingsCommand()
{
返回新列表();
}
如果你想看一个如何完全实现这一点的例子,请看一看AdventureWorks参考实现。你能显示你的相关代码抛出了该异常吗?@SonerGönül我甚至还没有开始编写任何代码。所有代码都来自模板。但是当尝试运行该应用程序并单击设置时,它会显示为c鲁莽。很抱歉我没有回答我自己的问题,但我就是这么做的。