Copied to clipboard

Flag this post as spam?

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


  • Damiaan 442 posts 1302 karma points MVP 6x c-trib
    Nov 06, 2013 @ 11:41
    Damiaan
    9

    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=1.2.11.0, 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.

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

    Hope it helps someone!

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

    This caused pain! Thank you so much :)

  • Damiaan 442 posts 1302 karma points MVP 6x c-trib
    Jan 06, 2014 @ 12:52
    Damiaan
    102

    I knew it would help someone someday. :D

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

    Nice, simple and effective solutions, thanks!

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

    Thanks!!! you have saved my day!

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

    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 - http://msdn.microsoft.com/en-us/library/2fc472t2.aspx. (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 85 posts 199 karma points c-trib
    May 27, 2015 @ 17:01
    Chris Randle
    0

    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 1130 posts 3088 karma points
    Jun 12, 2015 @ 11:40
    Lee
    0

    Just had this problem!! Nightmare!!

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

  • Lee 1130 posts 3088 karma points
    Jun 12, 2015 @ 11:41
    Lee
    0

    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 442 posts 1302 karma points MVP 6x c-trib
    Jun 12, 2015 @ 11:55
    Damiaan
    0

    There is an issue logged about this: http://issues.umbraco.org/issue/U4-1324

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

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

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

    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
    0

    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 442 posts 1302 karma points MVP 6x c-trib
    Jun 20, 2016 @ 20:14
    Damiaan
    0

    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
    0

    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 442 posts 1302 karma points MVP 6x c-trib
    Jun 24, 2016 @ 18:45
    Damiaan
    1

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

  • Damiaan 442 posts 1302 karma points MVP 6x c-trib
    Jan 25, 2017 @ 18:49
    Damiaan
    0

    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
    Raimond
    0

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

  • Proxicode 128 posts 324 karma points
    Jan 31, 2017 @ 21:42
    Proxicode
    0

    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:

Draft