【发布时间】:2016-09-13 13:53:24
【问题描述】:
从一个空白的通用 Windows 应用程序开始,我添加了 Autofac 4.1、Autofac.Extras.CommonServiceLocator 4.0 和 MvvmLightLibs 5.3。然后我创建了以下 ViewModelLocator 类。
using Autofac;
using Autofac.Extras.CommonServiceLocator;
using GalaSoft.MvvmLight.Views;
using Microsoft.Practices.ServiceLocation;
namespace UwpTest
{
public class ViewModelLocator
{
public static IContainer Container { get; private set; }
public static bool IsBuilt { get; set; }
public ViewModelLocator()
{
if (!IsBuilt)
{
var builder = new ContainerBuilder();
builder.RegisterType<DialogService>().As<IDialogService>();
builder.RegisterType<NavigationService>().As<INavigationService>();
Container = builder.Build();
IsBuilt = true;
}
ServiceLocator.SetLocatorProvider(() => new AutofacServiceLocator(Container));
}
}
}
然后在 App.xaml 中,我将视图模型定位器添加为资源。
<Application
x:Class="UwpTest.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UwpTest"
RequestedTheme="Light">
<Application.Resources>
<ResourceDictionary>
<local:ViewModelLocator x:Key="ViewModelLocator" />
</ResourceDictionary>
</Application.Resources>
</Application>
此时我收到以下错误:
无法加载文件或程序集“Autofac,Version=4.1.0.0,Culture=neutral,PublicKeyToken=17863af14b0044da”或其依赖项之一。系统找不到指定的文件。
在运行时一切正常,但在设计时却不行。我仔细检查了所有软件包是否已恢复。如何找到设计者试图从中加载 Autofac dll 的位置?或者我对项目的设置方式有什么遗漏?
我已经通过MSDN guide to troubleshooting design time issues,尝试使用 Visual Studio 的第二个实例来调试问题,并以我能想到的各种方式搜索答案。
可以在here找到带有repo的repo。
【问题讨论】:
-
鉴于这是一个设计时问题,您是否按照the MSDN guide to troubleshooting design time issues 中的步骤操作或搜索过有关设计时加载失败的其他答案?
-
我不得不尝试使用另一个 Visual Studio 实例附加调试器。我没有成功。
-
您可能应该用您已经尝试过的东西的信息来更新您的问题,这样人们就知道从哪里开始寻找,而不是重做您已经完成的工作。
-
我知道它已经更新了。
-
无法重现您的问题,它在我这边运行良好。您是否将 .Net Core 更新到最新的 5.2.2?
标签: c# uwp mvvm-light autofac