Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
Markdown Monster - The Markdown Editor for Windows

WCF REST Services and Could no load file or assembly... Error?


:P
On this page:

I'm working with a few different WCF REST services for some demo code and I've been getting an inconsistent error, every few hours. I've been getting the old "Could not load file or assembly... or one of its dependencies. The system cannot find the file specified" errors when accessing the WCF .SVC file in an ASP.NET hosted WCF service:

Could Not Load

The odd thing about the error is that it only occurs with the Web Service (.SVC) file - the rest of the application and ASPX pages seem to work fine. The assembly in question always points at a dynamically compiled file that starts with App_Web_xxxxx  that is a result of ASP.NET's dynamic compilation.

I'm using Web Application Projects (WAP), which require full re-compilation of all CodeBehind code before any code can execute. Yet,  even through I do a 'Build' in Visual Studio that I get this apparent assembly versioning error.

The pisser about this is that this error is triggered 'hidden' when making an AJAX callback that's trying to access the service. The page loads and then fails with client script errors that fail to load the ASP.NET AJAX proxy script code (ie. the /jsdebug call fails to load the javascript proxy code).

Luckily there's a fix: Do a full recompile (Rebuild All in Visual Studio) of the entire project after which the service works just fine. It's a FULL recompile that's required though. If I just do a regular incremental build - no good. If I just do a compile the Web WAP Project - no good. All four projects have to be recompiled.

Unfortunately the error always ends up returning, even though nothing else has changed - none of the other project dependencies are updated yet the recompile fixes the problem. My first thought is that it's one of those rare problems where the ASP.NET temporary file folder gets hosed, but even restarting IIS doesn't solve this particular problem either.

So, I enabled the Fusion Logs to check out what's failing to load. To so I opened up the fusion log viewer (fuslogvw.exe from the Windows SDK) enabled Fusion logging  and provide full assembly linking information in a log file. 

*** Assembly Binder Log Entry  (4/7/2008 @ 12:22:39 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable  c:\windows\system32\inetsrv\w3wp.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = NT AUTHORITY\NETWORK SERVICE
LOG: DisplayName = App_Web_cueuyz3g, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/projects2008/Articles/WcfAjax/WcfAjax/
LOG: Initial PrivatePath = C:\projects2008\Articles\WcfAjax\WcfAjax\bin
LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\wcfajax\3a2866fa
LOG: Cache Base = C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\wcfajax\3a2866fa
LOG: AppName = 6c86f508
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\projects2008\Articles\WcfAjax\WcfAjax\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v2.0.50727\Aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
ERR: Unrecoverable error occurred during pre-download check (hr = 0x80070002).

Nothing helpful here really. It just seems to indicate that the application is looking for a dynamic assembly that - for whatever reason even after a Web project compile - is no longer there.

The question that bugs me though: Is it just a condition that occurs because one of the markup pages (the SVC or ASPX pages) are changing or is the problem more involved where an ASP.NET forced recompile can introduce this problem. IOW, is this just a development problem or something that can rear its ugly head in live deployment? Since it's so inconsistent and only occurs every few hours or so it's hard to do a lot more discovery on this issue.

Incidentally the service is the only thing that doesn't work - the ASP.NET pages that use the same business objects and other project assemblies work just fine.

Anybody ever seen this particular problem?

Posted in ASP.NET  

The Voices of Reason


 

Olivier
April 08, 2008

# re: WCF REST Services and Could no load file or assembly... Error?

Yep, try to put it in your web.config the following line (directive batch) :

<system.web>
<compilation defaultLanguage="c#" debug="false" batch="false"/>
</system.web>

Corey Gaudin
April 08, 2008

# re: WCF REST Services and Could no load file or assembly... Error?

Any comments Olivier on why that works? The only thing there that I can gather is that no adding pdb debug files and not allowing it to compile in batch fixes it. But why?

Richard Deeming
April 08, 2008

# re: WCF REST Services and Could no load file or assembly... Error?

Assuming you don't have .NET 2.0 SP1 on the server, you might want to install hotfix KB934839:

http://support.microsoft.com/kb/934839
https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=6106

This also lists batch="false" as a workaround. This results in a separate assembly being compiled for every page and control, whereas the default is to compile each directory into a single assembly.

With batch compilation on, if one directory gets recompiled, and second directory which depends on the first doesn't, the new assembly will have a different name, so you'll see this error. With batch compilation off, each assembly will have a fixed name, so you won't see the error.

Justin Etheredge
April 08, 2008

# re: WCF REST Services and Could no load file or assembly... Error?

Yep, it is a pretty well known compilation bug in asp.net 2.0. The hotfix that Richard posted should certainly fix it, but even after this hotfix we have occasionally still seen the bug. ScottGu has a post a while back on it here: http://weblogs.asp.net/scottgu/archive/2007/04/11/public-hotfix-patch-available-for-asp-net-compilation-issues.aspx

On production servers if you get the error the only way to fix it is to either flip the batch switch that they talked about above, or clear out the asp.net cache on the server to force a recompile.

Radhakris
April 08, 2008

# re: WCF REST Services and Could no load file or assembly... Error?

Had the same problem when invoking the wcf service within an ASP.Net Site in the development environment. Added the following attribute to the .svc file to force the activation model.

Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory"


and deleted the temporary ASP.Net files for this web application.

Rick Strahl
April 08, 2008

# re: WCF REST Services and Could no load file or assembly... Error?

<sigh> I had hoped that by using WAP I'm bypassing the worst of the dynamic naming and dependency compilation issues but apparently not.

This makes some sense now though - I do pages spread across multiple directories and most likely the problem occurs when I make a change to the master page in the root that affects some of the child pages in the other directories. The odd thing though is that the only thing that fails is the WCF .SVC. The ASPX (using the master page) page works. It must be some dependency of the service, except this service has no code other the CodeBehind that goes into the WAP assembly that it depends on. <shrug>

So, how likely is this is to occur in production? Unlikely it would seem since all files would recompile together and then not change - hmm... unless you drop some updated file into the app at a later point.

Andy Miller
April 08, 2008

# re: WCF REST Services and Could no load file or assembly... Error?

Even with WAP, I think the service serializers are built on the fly. I suspect that is what is (not) being loaded.

anil
April 30, 2008

# re: WCF REST Services and Could no load file or assembly... Error?

I get this error even with standalone selfhosted WCF application. No clue why it happens

Ram Poornalingam
January 26, 2009

# re: WCF REST Services and Could no load file or assembly... Error?

Hi Rick,
I am Program Manager from WCF hosting team. can you provide me with a repro for the above issue ? Looks like the ASP.NET QFE did not fix your problem. right ?

thanks
-Ram

Kevin
January 12, 2010

# re: WCF REST Services and Could no load file or assembly... Error?

Hi Rick,

I get this exact error in production pretty consistently - the pages are fine but the wcf service is unreachable. clearing asp temp files is getting old...

I've just added the batch=false attrib to the compilation tag - but was wondering if you were able to come up with anything better - or have any more info on the subject.

Thanks for your blog

Kevin

# home based data entry jobs

To start the year off right, just as every year, getting your business goals planned out is top priority. If this is the first time reading something about this or you personally don’ t care to set up goals or a plan of action, read this post and reconsider giving it a try to make this[...]

Giuliano Gro
August 01, 2010

# re: WCF REST Services and Could no load file or assembly... Error?

Hi, did you solve the problem ? i had the same issue and the only way to solve was to clear the asp.net temporary folder and to restart iis ! it's not a good thing in a production environment :(

Giuliano Gro
November 17, 2010

# re: WCF REST Services and Could no load file or assembly... Error?

...in my environment i solved the problem by cleaning up the asp.net temporary files on each new release of software...hope this helps :)

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024