将 PRISM 6 与 UWP 一起使用时应用程序崩溃

Aplication crash on using PRISM 6 with UWP

我在新的 UWP 项目中引用了以下库。

用 PrismUnityApplication 替换应用程序 class 的基础 class 后,我在代码

中发现了一个异常
            var resourceLoader = ResourceLoader.GetForCurrentView(Constants.InfrastructureResourceMapId);

在下面的方法中

  public void RegisterFrame(IFrameFacade frame, String sessionStateKey)

在class

 public class SessionStateService : ISessionStateService

错误消息是:未找到 ResourceMap。

我是不是漏了一步

我想你在设置中做错了什么,因为我无法用稳定版和预发布版包重现错误。如 Prism 的 readme page 所述,您应该只安装 Prism.Unity 包,其余的将被相应地拉入。

Note that adding the container-specific package to your project, will also pull in the correct platform-specific package and the core PCL library. E.g. when you'd like to use Unity in a WPF project, add the Prism.Unity package and the rest will be pulled in as well.

这确实会引入您提到的引用,但仅添加 Prism.Unity 包作为项目引用。您的 project.json 文件应该如下所示(取决于使用稳定版还是预发布版,您当然会有不同的版本):

{
  "dependencies": {
    "Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0",
    "Prism.Unity": "6.2.0-pre1"
  },
  "frameworks": {
    "uap10.0": {}
  },
  "runtimes": {
    "win10-arm": {},
    "win10-arm-aot": {},
    "win10-x86": {},
    "win10-x86-aot": {},
    "win10-x64": {},
    "win10-x64-aot": {}
  }
}

下一步确实是在 C# 和 XAML 文件中用 PrismUnityApplication 替换基础 class。从 App class 中删除除构造函数和 OnLaunchApplicationAsync 方法之外的所有内容:

sealed partial class App : PrismUnityApplication
{
    public App()
    {
        this.InitializeComponent();
    }

    protected override Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args)
    {
        NavigationService.Navigate("Main", null);
        return Task.FromResult<object>(null);
    }
}

运行 现在的应用程序,给你这个错误,因为 MainPage 文件还没有移动。

An exception of type 'System.ArgumentException' occurred in Prism.Windows.dll but was not handled in user code

Additional information: The page name Main does not have an associated type in namespace App2.Views

在 Views 文件夹下添加一个新的空白页,一切都应该 运行 没问题。请仔细按照上述步骤重试。

您可以在 https://github.com/PrismLibrary/Prism-Samples-Windows

找到样本

巴特,我认为 arshadbadarkhan 和我们遇到了同样的问题。

arshadbadarkhan,如果您和我们一样,您正在尝试在 AdventureWorks 参考实现之后为您的新 Prism6 应用程序建模。我们通过从 AW 添加一个容易被忽视的文件夹和文件来解决这个运行时问题。当我们复制这个文件时:

...\Prism-Samples-Windows-master\Prism-Samples-Windows-master\AdventureWorks.Shopper\AdventureWorks.Shopper\Strings\en-US\Resources.resw

到我们新产品的主要应用程序项目中的 Strings/en-US 文件夹,我们避免了 ResourceMap not found 错误。现在我们可以利用 AW 使用的任何默认字符串,并且我们有一个存储库以在将来添加我们自己的字符串。