1

Getting following build error.

Error 15 Unknown build error, 'Could not load file or assembly 'log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'

I dont quite get whats going on. I tried using GUI for references, it didn't help. Spent 1.5 hours on this already and issue is still present.

I go directly to project file now and the only reference to log4net there is the following:

<Reference Include="log4net, Version=1.2.12.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\..\ExternalDlls\.NET 4.0\log4net.dll</HintPath>
</Reference>

I still get this error. Why does it even mention V1.2.11?

Thanks in advance

Valentin Kuzub
  • 11,703
  • 7
  • 56
  • 93
  • I checked all relevant log4net questions here. Looks like something special, although a lot of issues with referencing this log4net clearly exist. – Valentin Kuzub Sep 20 '13 at 02:27
  • Why don't you force your .net application to load Version=1.2.12.0 ? You can change web.config / app.config. More info here - http://msdn.microsoft.com/en-us/library/7wd6ex19.aspx – Varun Sharma Sep 20 '13 at 02:29
  • Some info is given here as well - http://stackoverflow.com/questions/8743992/how-do-i-work-around-log4net-keeping-changing-publickeytoken and I think that guy has similar problem to yours. – Varun Sharma Sep 20 '13 at 02:30
  • try to install Log4net via Package manager https://www.nuget.org/packages/log4net – Damith Sep 20 '13 at 02:32
  • Damith, while that indeed could actually fix things magically I would prefer to figure out what exactly is going on here, cause I dont like to feel stupid. I got a proj file that doens't refernece 1.2.11 . When I build project it throws error about it. I want to know what is up.. – Valentin Kuzub Sep 20 '13 at 02:33
  • This sounds curious: http://stackoverflow.com/questions/3158928/referencing-2-differents-versions-of-log4net-in-the-same-solution – Valentin Kuzub Sep 20 '13 at 02:48

4 Answers4

3

Okay got build working finally.

I went through all other projects and did Resharper - Remove unused references action.

After it was done, project started to build.

Valentin Kuzub
  • 11,703
  • 7
  • 56
  • 93
  • Yeah. clearly related to issue described in question!.. don't you just love VS sometimes. – Valentin Kuzub Sep 20 '13 at 03:30
  • 1
    Do you use crystal reports by any chance? I am getting the same issue as VS 2012 is adding reference path to another log4net.dll used by crystal reports causing the error. Its adding when I edit a report. If I remove reference path, error goes away. Unfortunately I have to do it every time I edit a crystal report. PS: I am using NuGet to maintain log4net in all projects. – Pradeep Jan 08 '14 at 01:03
  • Why would anyone want to use log4net in .NET apps when the System.Diagnostics Trace Class is so much simpler and better? – Dan Randolph Mar 25 '16 at 22:36
1

Can you check what version actually exists in the Path ....\ExternalDlls.NET 4.0\log4net.dll mentioned and see what version is present in GAC.

Remove the version in GAC, remove the below reference the from project file and add it again from the ExternalDlls folder

<Reference Include="log4net, Version=1.2.12.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\..\ExternalDlls\.NET 4.0\log4net.dll</HintPath>
</Reference>
Carbine
  • 7,849
  • 4
  • 30
  • 54
  • While I like GAC idea cause thats something external to proj file, I never put log4net there and it isn't there in fact after I checked: C:\Windows\system32>gacutil /l log4net Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.17929 Copyright (c) Microsoft Corporation. All rights reserved. The Global Assembly Cache contains the following assemblies: Number of items = 0 Please correct my command if its wrong. – Valentin Kuzub Sep 20 '13 at 02:38
  • Yes version exists. I got 15 projects in solution each referencing it just fine, just one project misbehaves for some reason. – Valentin Kuzub Sep 20 '13 at 02:41
  • I am sorry I am not aware of the command, but you can open it `C:\Windows\assembly` and you can see manually into the list of assemblies installed in `GAC` – Carbine Sep 20 '13 at 02:48
  • Yep ty for easy shortcut. Not there sadly. Command works too. – Valentin Kuzub Sep 20 '13 at 02:49
  • Can you check the bin folder of your project for log4net project and see what version it is? It should be the same as `ExternalDlls`version. If not try to find the source of the other dll and remove it. – Carbine Sep 20 '13 at 02:53
1

If you are creating a nuget package that is referencing log4net make sure your nuspec file is specifying the correct version of log4net (this is the problem I ran into after log4net released the new build). And make sure that if you don't want the latest version of log4net you encapsulate your version with "[" and "]" so that it doesn't get the latest. See this.. http://docs.nuget.org/docs/reference/versioning#Specifying_Version_Ranges_in_.nuspec_Files

Hope this helps someone.

dcinadr
  • 665
  • 2
  • 7
  • 24
0

I am facing this issue today. To solve this problem I deleted log4net.dll file reference from Bin Folder through visual studio. and rebuild the website. It automatically picks up log4net dll. This solved problem. Reason for this issue was Reference bind through visual studio may not be upto date with the actual file version.

Raj
  • 41
  • 4