我最近遇到了以下结构的代码:FooService.cs
FooService.svc
Default.aspx
文件内容:[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"; %>
我们在Windows Server 2003上使用.Net 4.0(调试)和IIS6,并带有“ fooservice”网站和主机文件条目,以通过http://fooservice/FooService.svc调用Web服务,并通过http://fooservice/调用
default.aspx
。此时一切正常。但是,执行以下步骤后,
更改default.aspx中的代码,保存文件
加载http://fooservice/(触发ASP.NET编译)
回收应用程序池
对http://fooservice/FooService.svc的调用失败,并引发以下异常
[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
这到底是怎么回事?
备注
我知道ASP.NET正在编译并加载新的
App_Web_*.dll
(在第2步中),但是为什么它要在回收(3.)之后尝试加载旧的(已删除的)App_Web_*.dll
?在
FooService.svc
中使用完全相同的代码内联而不是单独的FooService.cs
不会出现此问题(?)删除对
FooEngine
的静态引用也会使此问题消失(?) 最佳答案
我只是有同样的问题,
该应用程序是一个Web应用程序,因此已完全预编译。
这为我解决了问题,但是我不确定为什么:
<compilation debug="false" batch="false">
我从这里得到了这个解决方案:http://web.archive.org/web/20140116171941/http://www.creative-jar.com/insights/labs/programming/could-not-load-file-or-assembly-app_web_/