【发布时间】:2017-05-11 21:33:58
【问题描述】:
如果我执行以下步骤,我会收到异常:
测试 1:
MainApp-项目:
- 添加了 Nuget 包 Autofac 版本 4.5.0
- 添加了 Nuget 包 Autofac.WCF 4.0 版
模块-项目:
- 添加了 Nuget 包 Autofac.WCF 版本 4.0(将自动安装 Autofac 3.3.1)
- 通过 Nuget Manager Autofac 更新到 4.5.0 在通过 Directorycatalog 加载模块期间,MainApp 的引导程序会引发此异常。
Autofac.WCF 有依赖 Autofac >=3.3.1 &&
Bootstrapper.cs 中的异常: Prism.Wpf.dll 中出现“System.IO.FileLoadException”类型的未处理异常
附加信息:Die Datei oder Assembly "Autofac, Version=3.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da" oder eine Abhängigkeit davon wurde nicht gefunden。 Eine bestimmte Datei konnte nicht gefunden oder geladen werden。 (Ausnahme von HRESULT: 0x80131621)
测试 2:
我也尝试了这些步骤:
主应用程序:
- 使用 nuget 管理器安装 Autofac 4.5.0
- 使用 nuget 管理器安装 Autofac.WCF
模块:
- 使用 nuget 管理器安装 Autofac 4.5.0
- 使用 nuget 管理器安装 Autofac.WCF
可能是我做错了,因为我是第一次使用 Autofac 和 Autofac.WCF。我在unity IoC之前用过。
Bootstrapper.cs:
using Autofac;
using Prism.Autofac;
using PrismAutofacApp2.Views;
using System.Windows;
using Prism.Modularity;
namespace PrismAutofacApp2
{
class Bootstrapper : AutofacBootstrapper
{
protected override DependencyObject CreateShell()
{
return Container.Resolve<MainWindow>();
}
protected override void InitializeShell()
{
Application.Current.MainWindow.Show();
}
protected override IModuleCatalog CreateModuleCatalog()
{
var modulecatalog = new DirectoryModuleCatalog() { ModulePath = @".\Modules" };
return modulecatalog;
}
}
}
模块:
using Prism.Modularity;
using Prism.Regions;
using System;
using Autofac;
namespace PrismModule2
{
public class PrismModule2Module : Module
{
IRegionManager _regionManager;
public PrismModule2Module(IRegionManager regionManager)
{
_regionManager = regionManager;
}
}
}
更新
我按照注释中的要求卸载了软件包,然后按照测试 2 中提到的步骤重新安装了所有内容。问题仍然存在。
如果我通过删除覆盖方法 CreateModulecatalog 停用了模块加载,则问题不再发生,这意味着 MainApp 中的 Autofac 4.5.0 + Autofac.WCF 4.0.0 有效,但如果我加载模块(包括. Autofac 4.5.0 和 Autofac.WCF) 与 CreateModulecatalog Autofac 4.5.0 和 Autofac.WCF。
请记住,Module 没有 app.config,因为它是一个模块 (dll) 项目。
让一个项目满足以下要求对我来说非常重要:
主应用程序:
- Autofac 4.5.0 + Autofac.WCF 4.0.0 + Prism.WPF
- 模块应从目录加载
- MainApp 启动一个可执行文件
模块:
- Autofac 4.5.0 + Autofac.WCF 4.0.0(命名管道)+ Prism.WPF
- 模块必须承载 WCF 服务,因为 mainapp 启动一个可执行文件,而这些可执行文件必须使用 wcf 服务 + ioc。
对我来说一切都被阻止了,因为无法在 mainapp(引导程序)中毫无例外地使用 autofac + autofac.wcf 加载模块。
如果有人可以支持我,那么我可以使用共享桌面设置 teamviewer 会话来解决我的问题并为我提供指导。
【问题讨论】:
-
在您的配置文件中设置一个bindingRedirect 指向最新版本的 Autofac 或删除所有 NuGet 包并再次读取它们。 NuGet 经常无法为您正确更改 bindingRedirects。
-
我在两个项目(Autofac + AutoFac.WPF)中都卸载了,并按照我在第二点下的线程中提到的步骤进行操作。奇怪的是,如果我禁用模块的加载,主应用程序不会崩溃。模块 (DLL) 没有 app.config,因为它是一个模块。