15

I've got a web site that sporadically throws the following error:

Server Error in '/' Application.

Could not load file or assembly 'ICSharpCode.SharpZipLib, Version=0.85.3.365, Culture=neutral, PublicKeyToken=1b03e6acf1164f73' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Now I know that I do have a dependency on this DLL, but I have version 0.85.5 on my system. I have systematically deleted every older version of the DLL from the server, recompiled everything and republished. But no matter what I do, it seems that after every republish, the first one or two times that someone visits the site, they get this error. Then after refreshing once or twice, the error goes away and the site functions as normal.

What makes it even more weird is if I look at the line of code where the error is thrown:

URLRewriter.ProcessRewritingResult(status, excludedEnum, siteName, viewMode, relativePath);

URLRewriter is a class from a 3rd party package (Kentico CMS - CMS.URLRewritingEngine.dll). I ran Dependency Walker on that DLL and found no dependencies whatsoever on ICSharpCode.SharpZipLib.

Any ideas how to fix this?

EDIT: At @JeremyThompson's suggestion, I ran Process Monitor to catch the error. Here's a screen dump, with relevant pieces highlighted (and one folder name obscured for privacy reasons). You can view it full size by right-clicking on it, etc...

enter image description here

EDIT: Here's a load trace from the error. Does this help?

=== Pre-bind state information ===

LOG: User = MY-SERVER-12\Administrator

LOG: DisplayName = ICSharpCode.SharpZipLib, Version=0.85.3.365, Culture=neutral, PublicKeyToken=1b03e6acf1164f73 (Fully-specified)

LOG: Appbase = file:///C:/inetpub/wwwroot/MySite/

LOG: Initial PrivatePath = C:\inetpub\wwwroot\MySite\bin

Calling assembly : CMS.WebAnalytics, Version=6.0.4377.2467, Culture=neutral, PublicKeyToken=834b12a258f213f9.

===

LOG: This bind starts in default load context.

LOG: Using application configuration file: C:\inetpub\wwwroot\MySite\web.config

LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config

LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.

LOG: Post-policy reference: ICSharpCode.SharpZipLib, Version=0.85.3.365, Culture=neutral, PublicKeyToken=1b03e6acf1164f73

LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/9760eb69/275bb3db/ICSharpCode.SharpZipLib.DLL.

LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/9760eb69/275bb3db/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.DLL.

LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/MySite/bin/ICSharpCode.SharpZipLib.DLL.

LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/MySite/bin/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.DLL.

LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/9760eb69/275bb3db/ICSharpCode.SharpZipLib.EXE.

LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/9760eb69/275bb3db/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.EXE.

LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/MySite/bin/ICSharpCode.SharpZipLib.EXE.

LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/MySite/bin/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.EXE.

McNeight
  • 21
  • 3
Shaul Behr
  • 33,989
  • 61
  • 233
  • 360
  • Hi Shual, this just to ping the Kentico team, I've dealt with them in the past and they are top blokes. I'm sure they would take a look at this now its in a public forum. This guy: @PetrPalas (http://stackoverflow.com/users/1430236/petr-palas), he is really nice. – Jeremy Thompson Jul 18 '12 at 11:51

7 Answers7

5

So it turns out that Kentico has its own dependency on ICSharpCode.SharpZipZip.dll - and it's expecting to find the older version. I found a similar solution here. By inserting the following block into my web.config file, it seems I have finally banished this error!

<runtime>
  <assemblyBinding>
    <dependentAssembly>
      <assemblyIdentity name="ICSharpCode.SharpZipLib" publicKeyToken="1b03e6acf1164f73"/>
      <bindingRedirect oldVersion="0.85.3.365" newVersion="0.85.5.452"/>
    </dependentAssembly>
  </assemblyBinding>
</runtime>

What I still don't understand is, why didn't Dependency Tracker show up this dependency?

EDIT: Oh dear, this didn't solve it after all. It seems to happen less frequently now, but after restarting IIS today, one of our testers got the old error message again! :-(

Community
  • 1
  • 1
Shaul Behr
  • 33,989
  • 61
  • 233
  • 360
  • 1
    This is what I would have doen for the binding redirect => anything from 0 to .85.5.452 (which means it would include .85.3.365 ... use 85.5.452. eg. `` – Pure.Krome Nov 05 '13 at 09:58
5

Now I know that I do have a dependency on this DLL, but I have version 0.85.5 on my system. I have systematically deleted every older version of the DLL from the server, recompiled everything and republished.

Sounds like the 'dependency' is expecting the OLDER version of the DLL. Why not REPLACE all copies of the NEWER version (0.85.5) on your system, with the OLDER version (0.85.3.365)? (Make sure to check both the 'bin' folder of your web application and the 'GAC': c:\windows\assemblies)

If you need, you can download the older version here: http://sourceforge.net/projects/sharpdevelop/files/SharpZipLib/0.85.3/

NOTE:

  • After replacing the DLL, stop IIS and clear all Temporary ASP.Net files. E.g.: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files
  • ALSO: Remember to update your Visual Studio Solution so that it references the older version.

Cheers

Pete

Peter
  • 162
  • 7
  • Well, as it turns out, I don't need anything in the newer version of the DLL, so this solution actually works for me. Even though this is a very unsatisfying solution from an intellectual point of view, it does the trick, and so answer credit and bounty to you. Thanks! – Shaul Behr Jul 22 '12 at 08:14
4

You mention that the first one or two times a user visits the site you get the error.

To fix the problem I suggest you run Process Monitor and see where its looking to find and load the assembly.

-iisreset
-start Process Monitor on the server
-view a couple of pages and reproduce the problem as quickly as possible
-stop the ProcessMonitor trace
-search in the process monitor trace for ICSharpCode.SharpZipLib

If that fails, see what else was the cause:

-save the ProcessMonitor results as CSV
-open the CSV in Excel
-filter all columns
-choose the drop down list of the column with the Access Denied or ...

This should tell you what the problem is with the error Could not load file or assembly

Jeremy Thompson
  • 52,213
  • 20
  • 153
  • 256
  • Thanks for the advice. I do indeed find that the IIS Worker Process (w3wp.exe) is looking for v0.85.3 of that DLL in both the registry and the file system and gets "NAME NOT FOUND" or "PATH NOT FOUND".... until a couple hundred microseconds later when it finds version 0.85.5 of the DLL. What does that tell us? – Shaul Behr Jul 15 '12 at 08:10
  • 1
    Actually, it appears to be attempting (and failing) to "Create File" in the GAC, then in the .NET temporary files folder, before successfully doing a "create file" in the bin folder of my web site. Why "create file", rather than "read file"? – Shaul Behr Jul 15 '12 at 08:17
1

I think you were on the right track with the binding redirect. However, let me suggest that instead of binding your app against the older version, you attempt to bind the dependent assembly against the newer version.

Usually, forcing the older version is the worse choice, because while it might fix the depdenent assembly, you can inject compatibility errors in to code that depends on the newer version.

Brandon Langley
  • 544
  • 3
  • 9
  • I don't understand... I *am* binding against the newer version...? Or did I get something mixed up in my code there? – Shaul Behr Jul 17 '12 at 15:55
0

Try attaching to AppDomain.CurrentDomain.AssemblyResolve, so you can see when/what assembly loads and explicitly set load location.

user626528
  • 13,004
  • 25
  • 70
  • 133
  • How? Where? Code sample please? – Shaul Behr Jul 17 '12 at 09:24
  • 1
    Or use Assembly Binding Log Viewer (Fuslogvw.exe) to see how the assemblies are being probed http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.71).aspx ---- and see ---- http://stackoverflow.com/questions/255669/how-to-enable-assembly-bind-failure-logging-fusion-in-net – Colin Smith Jul 17 '12 at 12:03
  • 1
    This post isn't an actual attempt at answering the question. Please note [Stack Overflow doesn't work like a discussion forum](http://stackoverflow.com/about), it is a Q&A site where every post is either a question or an answer to a question. Posts can also have [comments](http://stackoverflow.com/help/privileges/comment) - small sentences like this one - that can be used to critique or request clarification from an author. This should be either a comment or a [new question](http://stackoverflow.com/questions/ask). – Rohan Khude Dec 14 '17 at 16:42
0

Are the Kentico CMS and your Application defined in the same Application Pool? Try running your Application in its own Application Pool.

What could be happening is when a worker process is recycled, sometimes your application is the first to be added, and sometimes the Kentico CMS is the first to be added, and this changes the way the ICSharpCode.SharpZipLib is resolved.

When you do the refreshing once or twice by chance your application gets loaded first that means it works.

What is Application Pool in IIS and Asp.Net?

UPDATE: Is your application a Web Site (compiled on first access), or Web Project (pre-compiled in Visual Studio). If it's a Web Site, then could you convert to a Web Project and try that ?

Community
  • 1
  • 1
Colin Smith
  • 11,811
  • 4
  • 34
  • 44
0

you can use the Fuslogvw.exe app that logging the assemblies loading and provide great details about load errors.

Read more here: http://msdn.microsoft.com/en-us/library/e74a18c4.aspx

Tamir
  • 3,525
  • 3
  • 28
  • 41