XAML设计器“无法加载文件或程序集Autofac 4.1".使用MVVMLight的UWP应用程序的App.xaml中 [英] XAML designer "Could not load file or assembly Autofac 4.1" in App.xaml of UWP application using MVVMLight

查看:249
本文介绍了XAML设计器“无法加载文件或程序集Autofac 4.1".使用MVVMLight的UWP应用程序的App.xaml中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从空白的通用Windows应用程序开始,我添加了Autofac 4.1,Autofac.Extras.CommonServiceLocator 4.0和MvvmLightLibs 5.3.然后,我创建了以下ViewModelLocator类.

Starting with a blank Universal Windows Application I added Autofac 4.1, Autofac.Extras.CommonServiceLocator 4.0 and MvvmLightLibs 5.3. I then created the following ViewModelLocator class.

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中,我将视图模型定位器添加为资源.

Then in the App.xaml I added the view model locator as a resource.

<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,版本= 4.1.0.0,区域性=中性,PublicKeyToken = 17863af14b0044da"或其依赖项之一.系统找不到指定的文件.

Could not load file or assembly 'Autofac, Version=4.1.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. The system cannot find the file specified.

在运行时一切正常,但在设计时一切正常.我仔细检查了所有软件包.如何找到设计者尝试从中加载Autofac dll的位置?还是我对项目的设置缺少什么?

Everything works fine at run time, but not at design time. I have double check that all packages have been restored. How can I find the location that the designer is attempting to load the Autofac dll from? Or what am I missing about how the project is setup?

我已经通过 MSDN指南解决设计时间问题,尝试使用Visual Studio的第二个实例调试问题,并以我能想到的所有方式搜索答案.

I have already been though the MSDN guide to troubleshooting design time issues, tried to debug the issue using a second instance of Visual Studio, and searched for answer in every way I can think of.

带有问题回购的回购可以在此处找到.

Repo with repo of the issue can be found here.

推荐答案

使用您的项目上传了我转载了您的问题.解决此错误的方法很简单,只需删除 Autofac 4.1.1 软件包即可没事的.

With your project uploaded I reproduced your issue. The solution for resolving this error is easy, just remove the Autofac 4.1.1 package it will be fine.

这是因为安装 Autofac.Extras.CommonServiceLocator NuGet软件包,它将帮助您同时安装包含Autofac软件包的依赖项.您不需要自己安装Autofac软件包.当您安装Autofac.Extras.CommonServiceLocator 4.0.0时,它将帮助您安装Autofac 3.5.0.如果您安装其他版本的Autofac软件包,则可能会导致歧义.

This is because when you install the Autofac.Extras.CommonServiceLocator NuGet package, it will help you install the dependencies which contain the Autofac package at the same time. You don't need to install the Autofac package by yourself. When you installed Autofac.Extras.CommonServiceLocator 4.0.0 it will help you install Autofac 3.5.0. If you install another version Autofac package it may lead ambiguity.

如果确实要同时添加两个软件包,请将Autofac版本从4.1.1更新为3.5.0.也可以,但我认为没有必要.

If you do want add two packages at the same time, please update the Autofac version from 4.1.1 to 3.5.0. And it will also be fine, but I don't think it is necessary.

有关我如何知道Auofac是版本3.5.0的信息,请参见下图.如果在安装Autofac.Extras.CommonServiceLocator 4.0.0之后尝试安装Autofac 4.11,您将收到有关Autofac的更新提示,从3.5.04.1.1.

For how I know the Auofac is version 3.5.0 please see the following picture. If you tried to install the Autofac 4.11 after the Autofac.Extras.CommonServiceLocator 4.0.0 installed, you will get a update prompt about Autofac from 3.5.0 to 4.1.1.

这篇关于XAML设计器“无法加载文件或程序集Autofac 4.1".使用MVVMLight的UWP应用程序的App.xaml中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆