gpt4 book ai didi

c# - 包引用版本中的歧义

转载 作者:太空狗 更新时间:2023-10-29 17:32:28 25 4
gpt4 key购买 nike

在一个项目中,有多个对Ninject库的引用,它们都有自己的版本,单元测试失败,这是错误:

Message: System.IO.FileLoadException : Could not load file or assembly 'Ninject, Version=4.0.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) ---- System.IO.FileLoadException : Could not load file or assembly 'Ninject, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

1-csproj文件

<Reference Include="Ninject, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
<HintPath>..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll</HintPath>
</Reference>

2- packages.config

<package id="Ninject" version="3.2.2.0" targetFramework="net462" />

3- app.config

<dependentAssembly>
<assemblyIdentity name="Ninject" publicKeyToken="c7192dc5380945e7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>

4-引用文件夹 -> 展开 -> 右击 Ninject -> 属性

Version: 3.2.0.0

5- 管理 NuGet 包 -> 安装 -> enter image description here

看起来我项目中的某处引用了版本 4.0.0.0 和 3.2.0.0我只想引用版本 3.2.2.0。

怎么做?

这些引用之间有什么区别?

最佳答案

我知道这是一篇旧帖子,但我认为这种见解对于解决问题非常有用。

在您的异常中,检查正在加载的程序集。该程序集需要它所依赖的特定版本的程序集,并在版本不正确时抛出异常。您很可能已经降级了从属程序集。即使 nuget 包和引用可能是正确的,重要的是 bin 文件夹中的程序集。

检查在清理解决方案/项目时是否删除了所有程序集。如果不是,则删除所有未删除的内容。

对于 ninject,问题很可能是在清理解决方案/项目时未删除的 Ninject.Web.Common.WebHost。项目中不直接引用,而是复制到bin文件夹中。

关于c# - 包引用版本中的歧义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46628076/

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