[英]After adding Prism.unity 6.2.0 to Windows 10 UWP, application throws exception
When creating a Universal Windows Application with Prism, I always receive an error upon running the application (or, sometimes, upon exiting the running application). 使用Prism创建通用Windows应用程序时,在运行该应用程序时(有时退出运行的应用程序时),我总是会收到错误消息。 Here are the steps I take to reproduce the problem: 这是我要重现该问题的步骤:
Code: 码:
using Microsoft.Practices.Unity;
using Prism.Events;
using Prism.Mvvm;
using Prism.Unity.Windows;
using Prism.Windows.AppModel;
using Prism.Windows.Navigation;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Threading.Tasks;
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.Resources;
using Windows.System;
using Windows.UI.Notifications;
using Windows.UI.Xaml;
namespace TestAppForPrism {
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App : PrismUnityApplication {
public App() {
this.InitializeComponent();
}
protected override Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args) {
NavigationService.Navigate("Main", null);
return Task.FromResult<object>(null);
}
protected override Task OnInitializeAsync(IActivatedEventArgs args) {
Container.RegisterInstance<INavigationService>(NavigationService);
return base.OnInitializeAsync(args);
}
}
}
When I run the application, an exception is thrown: 当我运行应用程序时,会引发异常:
Could not load file or assembly 'System.Runtime.Serialization.Xml, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. 无法加载文件或程序集“ System.Runtime.Serialization.Xml,版本= 4.1.1.0,区域性=中性,PublicKeyToken = b03f5f7f11d50a3a”或其依赖项之一。 The located assembly's manifest definition does not match the assembly reference. 找到的程序集的清单定义与程序集引用不匹配。 (Exception from HRESULT: 0x80131040) (来自HRESULT的异常:0x80131040)
Am I setting things up incorrectly? 我设置不正确吗?
The problem is that the default UWP template in Visual Studio 2015 still comes with "Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0"
, while this should be version 5.2.2. 问题是Visual Studio 2015中的默认UWP模板仍带有"Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0"
,而该版本应为5.2.2。
So simply update that package to 5.2.2 and everything should work. 因此,只需将该程序包更新为5.2.2,一切正常。
Small sidenote on your code: 代码上的小注释:
So your code can be trimmed down to 因此您的代码可以精简为
sealed partial class App : PrismUnityApplication
{
public App()
{
this.InitializeComponent();
}
protected override Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args)
{
NavigationService.Navigate("Main", null);
return Task.CompletedTask;
}
}
After playing around for a while, I think I found a solution: 玩了一段时间后,我想我找到了一个解决方案:
In the NuGet console, I ran "update-package -reinstall", and then rebuilt the solution. 在NuGet控制台中,我运行“ update-package -reinstall”,然后重新构建解决方案。 I still have a warning in the error window that says "Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.", but I seem to be able to run the application without receiving that exception any more. 我仍然在错误窗口中看到一条警告,提示“发现无法解决的相同从属程序集的不同版本之间存在冲突。将日志详细程度设置为详细时,这些引用冲突会在构建日志中列出。”以便能够运行应用程序而不会再收到该异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.