WCF REST Services and Could no load file or assembly... Error?
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:
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?
Other Posts you might also like
The Voices of Reason
# re: WCF REST Services and Could no load file or assembly... Error?
# re: WCF REST Services and Could no load file or assembly... Error?
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.
# re: WCF REST Services and Could no load file or assembly... Error?
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.
# re: WCF REST Services and Could no load file or assembly... Error?
Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory"and deleted the temporary ASP.Net files for this web application.
# re: WCF REST Services and Could no load file or assembly... Error?
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.
# re: WCF REST Services and Could no load file or assembly... Error?
# re: WCF REST Services and Could no load file or assembly... Error?
# re: WCF REST Services and Could no load file or assembly... Error?
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
# re: WCF REST Services and Could no load file or assembly... Error?
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
# re: WCF REST Services and Could no load file or assembly... Error?