I recently came across code of the following structure:
FooService.cs
FooService.svc
Default.aspx
Content of the files:
[FooService.cs]
using System.ServiceModel;
namespace FooService
{
[ServiceContract]
public class FooService
{
static FooEngine engine = new FooEngine();
[OperationContract]
public string Foo()
{
return "bar";
}
}
public class FooEngine
{
}
}
[FooService.svc]
<%@ ServiceHost Language="C#" Service="FooService.FooService" %>
[Default.aspx]
<%@ Page Language="C#" %>
<% var foo = "bar"; %>
We're using .Net 4.0 (Debug) and IIS6 on Windows Server 2003 with a 'fooservice' web and a hostfile entry to call the web service via http://fooservice/FooService.svc and default.aspx
via http://fooservice/. Everything works perfectly at this point.
However, after the following steps,
- Change code in default.aspx, save file
- Load http://fooservice/ (triggers ASP.NET compile)
- Recycle app pool
a call to http://fooservice/FooService.svc fails and throws the following exception
[FileNotFoundException: Could not load file or assembly 'App_Web_ynlv0b1k, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +39
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +132
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +144
System.Reflection.Assembly.Load(String assemblyString) +28
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +208
System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +1440
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +44
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +615
[ServiceActivationException: The service '/FooService.svc' cannot be activated due to an exception during compilation. The exception message is: Could not load file or assembly 'App_Web_ynlv0b1k, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified..]
System.Runtime.AsyncResult.End(IAsyncResult result) +679246
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +190
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, String routeServiceVirtualPath, Boolean flowContext, Boolean ensureWFService) +234
System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +355
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
What exactly is going on here?
Remarks
- I understand that ASP.NET is compiling and loading a new
App_Web_*.dll
(during step 2), but why is it trying to load the old (deleted)App_Web_*.dll
after the recycle (3.)? - using the exact same code inline in
FooService.svc
instead of a separateFooService.cs
does not have this problem (?) - removing the static reference to the
FooEngine
also makes this problem go away (?)