WCF IIS App_Web_xxxxxx_WTF?

This is very frustrating. We are now on my 5th try saving this post without losing everything. Here goes!

This post is probably a great example of how I like to write a blog entry for myself as well as the reader. I had been tinkering with embedding Silverlight into CRM 4.0 and it has been an enlightening experience (don’t worry, more posts on that to follow). At any rate, I had finally gotten it working how I wanted and I checked back the next day only to find that it was broken. The worst part being that I hadn’t changed anything! Now before you unsubscribe from this blog or decide to move on to the next search result, it turned out that I really hadn’t done anything, so read on.

OK, so what was this magical error that just suddenly popped up out of nowhere when I hadn’t done anything wrong? Well, Silverlight was giving me some “none too helpful” information (gotta figure out how to get better info there). I did notice that it was after the control loaded and looked to be at the point that the app reached out to my WCF service for some data. So, i decided to try and access the WCF service directly and that’s when I got the error. It looked something like this:

Server Error in ‘/ISV/MyApp’ Application.


Could not load file or assembly ‘App_Web_xxxxxxxx, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The system cannot find the file specified.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly ‘App_Web_xxxxxxxx, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The system cannot find the file specified.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Assembly Load Trace: The following information can be helpful to determine why the assembly ‘App_Web_xxxxxxxx, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ could not be loaded.

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].


Stack Trace:

[FileNotFoundException: Could not load file or assembly 'App_Web_xxxxxxxx, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.]
   System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
   System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +54
   System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +211
   System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +141
   System.Reflection.Assembly.Load(String assemblyString) +25
   System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +154
   System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +516
   System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +31
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +498

[ServiceActivationException: The service '/ISV/SilverlightService.svc' cannot be activated due to an exception during compilation.  The exception message is: Could not load file or assembly 'App_Web_xxxxxxxx, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified..]
   System.ServiceModel.AsyncResult.End(IAsyncResult result) +4413209
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +183
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +205
   System.ServiceModel.Activation.HttpHandler.ProcessRequest(HttpContext context) +77
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +358
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64

If you’re anything like me, your initial reaction was probably something like “App_Web_xxxxxxxx, WTF is that?”. If that sounded familiar, then you and I were in the same boat.

First response: start and stop the site. Result: no change.

Second response: rebuild and publish the site. Result: no change!

Third response: iisreset. Result: no change! grrrrr…

Fourth response: reboot the server. Result: no change! what the heck?

Now there are probably a few ASP.NET gurus that will (and are welcome to) comment on this and probably suggest that I’m foolish for not realizing what was going on. It stumped me for a few minutes, and that’s what I’m documenting. Anyway, my eyes shot to the Stack Trace and the secret for me was the exception. It’s a FileNotFoundException, which means that it was trying to find a physical file and couldn’t. Furthermore, I could see from the calls, like System.Reflection.Assembly.InternalLoad, that this wasn’t likely to be my code. Then it hit me. Part of the miracles of ASP.NET 2.0’s Site Pre-Compilation, your app gets compiled down and stored in the Temporary ASP.NET Files directory, typically at C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files.

We keep all of our custom files in the ISV virtual directory of the CRM 4.0 web site just as the guidance to do so describes. When I went back to check, CRM was behaving perfectly, as were all my custom pages except for my WCF services. This is where I begin speculating, but my guess is that at some point the WCF Service Host died a potentially horrible death at which point it cleaned up after itself including deleting its temporary compiled files. The ASP.NET web app on the other hand figured “nothing changed about me, so I’ll just leave those files in my temp directory and use them next time. Again, I don’t know if this is what actually happened, but it’s my best guess for now.

Deleting all the files from my Temporary ASP.NET files did in fact fix the issue, and I have yet to have it happen again. Knock on wood!

As it turns out, a bit more research revealed that there is in fact a hotfix, though people’s mileage has varied on this one. I didn’t apply it yet, but I will let you know if I have any more issues with this.

Hopefully this saves you some grief!

Cheers!


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s