.net 如何修复“无法解决之间的冲突”错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9828216/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 16:19:44  来源:igfitidea点击:

How to fix "No way to resolve conflict between" error?

.netmsbuildlog4net

提问by coding4fun

Recently added log4net.dll to our data object. Our data object builds perfectly but when you try to build anything that references our data object you get the following error:

最近将 log4net.dll 添加到我们的数据对象中。我们的数据对象构建完美,但是当您尝试构建任何引用我们数据对象的内容时,您会收到以下错误:

No way to resolve conflict between "log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" and "log4net, Version=1.2.9.0, Culture=neutral, PublicKeyToken=b32731d11ce58905". Choosing "log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" arbitrarily.

无法解决“log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304”和“log4net, Version=1.2.9.0, Culture=neutral, PublicKeyToken=b32731d11ce58905”之间的冲突。任意选择“log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304”。

I found the following threadthat enabled me to get more information about the problem.

我发现以下线程使我能够获得有关该问题的更多信息。

log4net is used for a variety of things in our project. For example, crystal installed 1.2.9 into the GAC. I know infragictics uses 1.2.10.

log4net 用于我们项目中的各种事情。比如水晶安装1.2.9到GAC。我知道 infragictics 使用 1.2.10。

We have a specific directory - call it c:\references- where we build all our dlls to and that all our applications use to reference our internal dlls. So I specifically set my reference in our data object to c:\references\log4net.dll which is version 1.2.11. Which is weird because in the error message above you don't see 1.2.11. The dll is referenced with specific version: = True & Copy Local:= True. I checked the build directory & 1.2.11 of log4net did get moved correctly.

我们有一个特定的目录 - 称之为c:\references- 我们将所有 dll 构建到其中,并且我们所有的应用程序都使用该目录来引用我们的内部 dll。因此,我特意将数据对象中的引用设置为 c:\references\log4net.dll,即版本 1.2.11。这很奇怪,因为在上面的错误消息中您没有看到 1.2.11。dll 引用特定版本:= True & Copy Local:= True。我检查了 log4net 的构建目录和 1.2.11 确实被正确移动了。

If it helps here are some of the detailed error messages:

如果有帮助,这里有一些详细的错误消息:

There was a conflict between "log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" and "log4net, Version=1.2.9.0, Culture=neutral, PublicKeyToken=b32731d11ce58905".
  No way to resolve conflict between "log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" and "log4net, Version=1.2.9.0, Culture=neutral, PublicKeyToken=b32731d11ce58905". Choosing "log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" arbitrarily.
      References which depend on "log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" [C:\Windows\assembly\GAC_32\log4net.2.10.0__692fbea5521e1304\log4net.dll].
          C:\Windows\assembly\GAC_MSIL\CrystalDecisions.Shared.0.2000.0__692fbea5521e1304\CrystalDecisions.Shared.dll

   References which depend on "log4net, Version=1.2.9.0, Culture=neutral, PublicKeyToken=b32731d11ce58905" [C:\Program Files (x86)\Business Objects\Common.0\managed\log4net.dll].          c:\references\DBObjectAdoNet.dll
            Project file item includes which caused reference "c:\references\DBObjectAdoNet.dll".

Update: So far the only way I found to fix the error is to reference log4net in anything referencing DBObjectAdoNet.dll. This isn't really a usable solution for us since almost everything in our entire system uses it.

更新:到目前为止,我发现修复错误的唯一方法是在引用 DBObjectAdoNet.dll 的任何内容中引用 log4net。这对我们来说并不是一个真正可用的解决方案,因为我们整个系统中的几乎所有东西都使用它。

2nd Update: Tried putting log4net in the GAC thinking that would fix the problem but still no go.

第二次更新:尝试将 log4net 放入 GAC 认为可以解决问题,但仍然无法解决。

3rd Update: I've made a support call to Microsoft. They want me to use Assembly.LoadFrom() which I'm very, very hesitant to do since we make over 300,000 calls in one application and would require reflection for each call which would slow things down quite a bit.

第三次更新:我已经给微软打了一个支持电话。他们希望我使用 Assembly.LoadFrom(),我非常非常犹豫要不要这样做,因为我们在一个应用程序中进行了超过 300,000 次调用,并且每次调用都需要反射,这会大大减慢速度。

I found out if I uninstall the crystal runtime on my machine the error goes away which doesn't make a lot of sense because the only thing it does, as far as I can tell, is remove log4net 1.2.10.0 from the GAC under the .NET framework 2.0 folders, which shouldn't matter because the app is a .NET framework 4 app.

我发现如果我在我的机器上卸载 Crystal 运行时,错误就会消失,这没有多大意义,因为据我所知,它唯一能做的就是从 GAC 下的 GAC 中删除 log4net 1.2.10.0 .NET framework 2.0 文件夹,这应该无关紧要,因为该应用程序是 .NET framework 4 应用程序。

采纳答案by coding4fun

We found out that crystal runtime was definitely the problem. If we uninstall log4net at %windir%\assemblythat crystal runtime installed then the warning message goes away. What's weird is that if I install log4net 1.2.10 from log4net's site into the GAC then the warning message doesn't reappear. If anyone can explain that then please add to this thread. Crystal signed log4net with their own strong name key (the public key token is different).

我们发现水晶运行时肯定是问题所在。如果我们在%windir%\assembly安装的那个水晶运行时卸载 log4net,那么警告消息就会消失。奇怪的是,如果我将 log4net 1.2.10 从 log4net 的站点安装到 GAC 中,则警告消息不会再次出现。如果有人可以解释,那么请添加到此线程。Crystal 使用自己的强名称密钥对 log4net 进行签名(公钥令牌不同)。

The key to fixing the log4net problem is that log4net is a open source project. Which means we can simply build the dll from source with a different name. Haven't tried it out yet but that should fix the problem. We'll have the extra step of building from source every time we want to update log4net but considering how much we are going to update the dll it isn't a big deal.

解决log4net问题的关键在于log4net是一个开源项目。这意味着我们可以简单地从具有不同名称的源代码构建 dll。还没有尝试过,但这应该可以解决问题。每次我们想要更新 log4net 时,我们都会有额外的步骤从源代码构建,但考虑到我们要更新多少 dll,这没什么大不了的。

回答by KMoraz

Open your project file (.csprojin C# or .vbprojin VB.NET) for editing.

打开您的项目文件(.csproj在 C# 或.vbprojVB.NET 中)进行编辑。

Make sure the log4net reference is Fully Qualified Type Name, has HintPathand SpecificVersion=True.

确保 log4net 引用是完全限定类型名称,具有HintPathSpecificVersion=True

<Reference Include="log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
  <HintPath>..\references\log4net.dll</HintPath>
  <SpecificVersion>True</SpecificVersion>
</Reference> 

Save the file and try to rebuild.

保存文件并尝试重建。

回答by Bizhan

Cause:

原因:

You have two differentassemblies with the same file name. The compiler does not know which one to choose to copy to the output directory so it gives that No way to resolve conflict between...error.

您有两个具有相同文件名的不同程序集。编译器不知道选择哪个复制到输出目录,所以它给出了那个错误。No way to resolve conflict between...

In my case, they were completelydifferent assemblies that happened to have the same file names.

就我而言,它们是完全不同的程序集,恰好具有相同的文件名。

In your case, you have two different versionsof the same assembly (log4net)

在您的情况下,您有同一个程序集的两个不同版本(log4net)

solution:

解决方案:

In my case, the solution was to simply renameone of the dll files.

就我而言,解决方案是简单地重命名其中一个 dll 文件。

In your case, the solution is to find out wherethe older assembly was referenced and correct it to reference the newer one.

在您的情况下,解决方案是找出引用旧程序集的位置并更正它以引用新程序集。

回答by Patrick Stalph

You will get this message as well when running a net framework v4.6.2 application that references netstandard2_0 libraries. Net462 does not fully support netstandard and thus quite some dlls are duplicated with different versions. Even if you don't reference something (e.g. System.Drawing) you might see conflicts. Consider upgrading to a higher net framework version (I've just changed to 4.7.2, which resolved this).

在运行引用 netstandard2_0 库的网络框架 v4.6.2 应用程序时,您也会收到此消息。Net462 不完全支持 netstandard,因此相当多的 dll 与不同版本重复。即使您不引用某些内容(例如 System.Drawing),您也可能会看到冲突。考虑升级到更高的网络框架版本(我刚刚更改为 4.7.2,它解决了这个问题)。