【发布时间】:2010-10-29 11:55:42
【问题描述】:
我最近遇到了以下结构的代码:
FooService.csFooService.svcDefault.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 和default.aspx 通过http://fooservice/ 调用网络服务。此时一切正常。
但是,经过以下步骤,
- 更改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的静态引用也会使这个问题消失 (?)
【问题讨论】:
-
可能问题与 FooEngine 有关?如果您在示例中将 FooEngine 更改为对象,错误会重现吗?
-
是的,
FooEngine是这里的问题。但我想知道为什么这是问题所在。 -
你解决了吗?我面临同样的问题
-
@ShayErlichmen 不是真的,我们只是在构建过程中添加了 aspcompile。