gpt4 book ai didi

c# - 强制第 3 方程序集使用另一个程序集的另一个版本

转载 作者:太空狗 更新时间:2023-10-29 20:04:43 26 4
gpt4 key购买 nike

我正在运行集成测试,当我到达那行代码时:

        WebApiDependencyResolverConfig.Register(config); 

(使用里面的autofac容器)

我得到这个异常:

{"Could not load file or assembly 'System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"}

融合日志:

=== Pre-bind state information ===
LOG: DisplayName = System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/TLP/TLP.API.IntegrationTests/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : Autofac.Integration.WebApi, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\TLP\TLP.API.IntegrationTests\bin\Debug\TLP.API.IntegrationTests.dll.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config

autofac web api 集成似乎只适用于 web api 2.0。当我使用不再引用 system.web.http 5.0.0 而是引用 5.1.0 的 web api 2.1 时,它不再起作用。

我如何告诉 autofac 使用 system.web.http 5.1.0 版本而不是 5.0.0?

我把它放在我的集成测试和 API 项目的 app.config 中:

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Http"
publicKeyToken="32ab4ba45e0a69a1"
culture="neutral" />
<bindingRedirect oldVersion="5.0.0.0"
newVersion="5.1.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>

但它没有用!

另一件非常奇怪的事情是,我读到过使用 .NET 4.5.1 这个重定向程序集的东西是自动完成的。但它没有发生......

最佳答案

我已将更新包推送到 NuGet for Web API 2.1 和 MVC 5.1。

http://www.nuget.org/packages/Autofac.WebApi2

https://www.nuget.org/packages/Autofac.Mvc5

Microsoft 显然对语义版本控制规则有不同的解释,因为 5.1 作为次要版本,应该“以向后兼容的方式添加功能”。 5.1.0 包不是这种情况,因为增加了强命名程序集版本。

Autofac程序集是强命名的,但在3.0系列版本期间,只更新包和文件版本。程序集版本始终保持在 3.0.0.0,以防止在包更新期间发生此类重大更改。不幸的是,我们无法控制 ASP.NET 依赖项,并且在发生此类情况时必须重新编译。

关于c# - 强制第 3 方程序集使用另一个程序集的另一个版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21390740/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com