wcf - 激活 WCF 服务期间出现 FileLoadException

标签 wcf iis activation fileloadexception

在 IIS 中部署 WCF 服务后,访问该服务时出现此错误:

Server Error in '/MyService' Application.

The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) 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.FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)

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.

Stack Trace:

[FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)]
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) +153 System.Type.GetType(String typeName) +89 System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +936
System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +76
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +901

[ServiceActivationException: The service '/MyService/MySvcImpl.svc' cannot be activated due to an exception during compilation. The exception message is: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047).]
System.Runtime.AsyncResult.End(IAsyncResult result) +650220
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +210733
System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +166

我打开了程序集绑定(bind)日志查看器 (FUSLOGVW.EXE),但它没有显示任何绑定(bind)失败。任何人都知道可能导致此问题的原因,或如何调试此问题?

最佳答案

发现问题了!在这里发帖是因为有一天它可能会对某人有所帮助。

我的 web.config 包含一个带有工厂属性的服务激活元素,如下所示:

<serviceHostingEnvironment>
  <serviceActivations>
    <add relativeAddress="MyService.SvcImpl.svc" 
         service="MyService.SvcImpl" 
         factory="MyCompany.MyServiceHostFactory, MyCompany.MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=" />
  </serviceActivations>
</serviceHostingEnvironment>

工厂属性包含来自强命名程序集的类引用。但是,PublicKeyToken 属性应该由构建系统设置为正确的值,具体取决于使用的是测试签名证书还是官方签名证书。 构建步骤不知何故失败,并使程序集的强名称无效。因此,异常消息的第一部分非常准确。它只是没有告诉我哪个程序集无法加载。 FUSLOGVW.EXE 在这里也没有任何帮助。

关于wcf - 激活 WCF 服务期间出现 FileLoadException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16116332/

相关文章:

user-accounts - 生成/存储账户激活码

c# - 禁止 WCF 客户端证书和用户名凭据

测试中看到的 WCF 位置

WCF、GET 和 HTTPS

c# - 在 WCF 中使用 ConcurrencyMode.Multiple 的优点和缺点

c# - 保存 xdocument 时访问被拒绝

asp.net - (405) 不允许的方法。 WCF网络服务

Azure 项目中静态文件的 IIS 错误 500.19