Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Damiaan 440 posts 1295 karma points MVP 4x c-trib
    Nov 06, 2013 @ 11:41

    log4net public token issues (could not load file or assembly)

    We have some packages (and external modules) which we use who are using log4net. But after installing these packages we have the following error: Could not load file or assembly 'log4net, Version=, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

    Apparently umbraco depends on a log4net version without public key and the log4net (nuget package) has public key.

    To use both log4net assemblies I solved this like this:

    1. get the umbraco version of log4net.dll and move it to a new folder: bin\log4net-1.2.11-nokey
    2. pull the new log4net nuget package (which is signed with a new key)
    3. Add the code below to the assemblyBinding section of the web.config:

    if you recompiled the log4net dll, you might need to update the publicKeyToken (you can use dotpeek or ILspy to find the publicKey easily.

            <assemblyIdentity name="log4net" publicKeyToken="null" culture="neutral"  />
            <codeBase version="" href="bin\log4net-1.2.11-nokey\log4net.dll" />
            <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" />
              <bindingRedirect oldVersion="" newVersion=""/>
              <codeBase version="" href="log4net.dll" />

    Hope it helps someone!

  • Charles Afford 1163 posts 1709 karma points
    Jan 06, 2014 @ 12:33
    Charles Afford

    This caused pain! Thank you so much :)

  • Damiaan 440 posts 1295 karma points MVP 4x c-trib
    Jan 06, 2014 @ 12:52

    I knew it would help someone someday. :D

  • Steve McGill 6 posts 57 karma points
    Mar 23, 2014 @ 21:09
    Steve McGill

    Nice, simple and effective solutions, thanks!

  • Emiliano 5 posts 25 karma points
    Dec 04, 2014 @ 15:14

    Thanks!!! you have saved my day!

  • Torben Rahbek Koch 4 posts 25 karma points
    Dec 15, 2014 @ 15:20
    Torben Rahbek Koch

    This does not work for me (trying with log4net 1.2.13). And I wonder how it could work at all, since binding redirects normally are ignored for assemblies with no public key token - (The .NET 4.5 description varies substantially from the .NET 4.0 description, making it unclear whether the behaviour has changed)

    And when it supposedly works: What happens when you have two log4net dll's flittering around in the same process? Will you have two e.g. FileAppenders competing over the same file?

    And why, in the first place, did Umbraco choose to have a log4net with no PublicKeyToken? And why bundle it, instead of having it as a nuget package dependency?

  • Chris Randle 67 posts 181 karma points c-trib
    May 27, 2015 @ 17:01
    Chris Randle

    I'm afraid this way does work with v1.2.13. You just need to set it correctly per DLL. I understand your frustration though.

    I think they use log4net in this original since they have to do to allow it to work under medium trust. Apparently, they should be dropping this in v8 so we might see NLog or something else. Yes it's a very annoying issue.

  • Lee 1124 posts 3061 karma points
    Jun 12, 2015 @ 11:40

    Just had this problem!! Nightmare!!

    Thanks for posting the solution, I think this needs submitting as a bug.

  • Lee 1124 posts 3061 karma points
    Jun 12, 2015 @ 11:41

    Oh and I used 1.2.13 and it does work. Just update the versions in the XML fragment supplied in the first post.

  • Damiaan 440 posts 1295 karma points MVP 4x c-trib
    Jun 12, 2015 @ 11:55

    There is an issue logged about this:

  • Alan Mac Kenna 147 posts 405 karma points MVP c-trib
    Jul 27, 2015 @ 12:41
    Alan Mac Kenna

    Thanks for this! I'd hit the same issue.

  • Dorian Farrimond 4 posts 24 karma points
    Oct 13, 2015 @ 14:45
    Dorian Farrimond

    Another big thanks for this, great use of binding redirects.

    I nearly failed to get automated builds working because of this.

    This is the post-build event I used to create an Umbraco folder in the output directly, taking a file within the project (lib\Umbraco.log4net.dll) as the source file

    echo f | xcopy /y $(ProjectDir)lib\Umbraco.log4net.dll $(TargetDir)Umbraco\log4net.dll

  • Alastair Todd 44 posts 142 karma points
    Feb 06, 2016 @ 13:49
    Alastair Todd

    Thank you for the fix. That problem cost me hours and hair loss.

    Why is this still persistent in v7.3.7 Feb 16 I wonder?

  • Damiaan 440 posts 1295 karma points MVP 4x c-trib
    Jun 20, 2016 @ 20:14

    Yes the problems will persist on every v7 release. Until v8 there won't be any fix for this as it would be a breaking change for many umbraco sites.

  • Ryan Brown 12 posts 82 karma points
    Jun 24, 2016 @ 15:29
    Ryan Brown

    And when will that be released? This has been broken for more than 3 years and causes significant pain any time someone needs to upgrade their Umbraco version. Surely a single breaking change to move to a more correct solution is better than having to hack in a fix with every upgrade?

  • Damiaan 440 posts 1295 karma points MVP 4x c-trib
    Jun 24, 2016 @ 18:45

    v8 release is planned for Q4 of 2016. Suffering is about to end. ;-)

  • Damiaan 440 posts 1295 karma points MVP 4x c-trib
    Jan 25, 2017 @ 18:49

    V8 is currently planned for Q1 of 2017. But when we include the changing rotation speed of the earth spinning... the best guess is after codegarden.

  • Raimond 6 posts 116 karma points
    Sep 28, 2016 @ 12:14

    Thanks for this solution. I thought I was going crazy!

  • Proxicode 123 posts 309 karma points
    Jan 31, 2017 @ 21:42

    Just to echo everyone else here - thanks so much!! I totally did not expect this to work, but it did. Wish I would have checked here sooner. Thanks again!

Please Sign in or register to post replies

Write your reply to: