我正在使用.NET Framework 4.6.2和log4net 2.0.8开发一个C#库项目。
当我尝试编译项目时,我收到以下错误:
错误CS0433:类型'log4net.ILog'存在于 'C:\ WINDOWS \装配\ GAC_32 \ log4net的\ 1.2.10.0__692fbea5521e1304 \ log4net.dll' 还有 D:\ DESARROLLO \包\ log4net.2.0.8 \ lib中\ net45满\ log4net.dll'
似乎GAC中还有另一个版本的log4net。
为什么要使用GAC版本进行编译?我有另外一个使用log4net的项目,只有在这个项目中我才会收到此错误。
log4net的引用是D:\Desarrollo\packages\log4net.2.0.8\lib\net45-full\log4net.dll
。它设置为本地副本。
我已经安装了软件包并再次添加了相同的错误。
详细错误是这样的:
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1964,5): warning MSB3243: No way to resolve conflict between "log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a" and "log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304". Choosing "log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a" arbitrarily.
1>D:\MyProject\Loggers\ActionLogHelper.cs(28,20,28,24): error CS0433: The type 'ILog' exists in both 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' and 'log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'
1>D:\MyProject\Loggers\ActionLogHelper.cs(30,26,30,30): error CS0433: The type 'ILog' exists in both 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' and 'log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'
1>D:\MyProject\Loggers\ExceptionLogHelper.cs(22,20,22,24): error CS0433: The type 'ILog' exists in both 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' and 'log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'
1>D:\MyProject\Loggers\ExceptionLogHelper.cs(24,29,24,33): error CS0433: The type 'ILog' exists in both 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' and 'log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
答案 0 :(得分:1)
问题是项目文件中有两个对同一个dll的引用。我用Notepad ++打开了项目文件,我在里面找到了这个:
<ItemGroup>
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<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>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="log4net">
<HintPath>..\..\..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
</Reference>
我删除了最后一个,现在它已编译。