WCF服务(IIS 7)中的莫名其妙程序集负载 [英] Inexplicable Assembly Load in WCF Service (IIS 7)

查看:80
本文介绍了WCF服务(IIS 7)中的莫名其妙程序集负载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个新的WCF Web服务,该服务将在现有的ASP.NET Web应用程序中托管.当我尝试为该服务运行.svc文件时,出现了一个例外,即它无法找到程序集的文件.

I'm working on a new WCF web service that's to be hosted within an existing ASP.NET web application. When I attempt to run the .svc file for the service, I'm getting an exception that it can't find the file for an assembly.

无法加载文件或程序集'System.IdentityModel,版本= 4.0.0.0,区域性=中性,PublicKeyToken = b77a5c561934e089'或其依赖项之一.该系统找不到指定的文件.

Could not load file or assembly 'System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.

问题是,此服务似乎没有在任何地方引用此(特定)程序集.有一个引用的项目加载System.IdentityModel,但它引用的版本是3.0.0.0.实际上,所有这些项目都针对3.5运行时,并且在任何地方都没有对任何4.0程序集的引用.

The trouble is, this service doesn't appear to reference this (particular) assembly anywhere. There is one referenced project that loads System.IdentityModel, but it references version 3.0.0.0. In fact, all of these projects target the 3.5 runtime and there are no references to any 4.0 assemblies anywhere.

这是Web应用程序的Web.config中的<compilation>标记:

Here is the <compilation> tag from the Web.config for the web application:

<compilation debug="true">
  <assemblies>
    <clear/>
    <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Messaging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
  </assemblies>
</compilation>

注意:<clear />标签是在以后作为故障排除尝试添加的.它似乎对行为没有任何影响.我添加它是因为IIS配置管理器的".NET编译"选项卡给我一个错误,提示System.Data被添加了两次,尽管显然不在此文件中.添加<clear />可以帮我解决这个问题,但是我在Machine.config中找不到有问题的重复项,并且没有基础网站Web.config,所以我想知道是否可能有我不在的地方看起来可能是问题的原因.

Note: The <clear /> tag was added later as a troubleshooting attempt. It did not appear to have any effect upon behavior. I added it because the ".NET Compilation" tab of the IIS configuration manager was giving me an error that System.Data was being added twice, though obviously not in this file. Adding <clear /> took care of it for me, but I couldn't find the offending duplicate it in the Machine.config and there is no base website Web.config, so I'm wondering if there might be somewhere I'm not looking that could be the cause of the problem.

服务器正在运行带有.NET 3.5 SP1的Server 2008.我在本地IIS安装上遇到了相同的问题(尽管使用System.Configuration而不是IdentityModel,但仍然...),该问题是在Windows 7 x64和.NET 4.0上进行的.

The server is running Server 2008 with .NET 3.5 SP1. I get the same issue (though with System.Configuration instead of IdentityModel, but nonetheless...) on my local IIS installation, which is on Windows 7 x64 with .NET 4.0.

有人知道为什么要尝试加载此程序集(仅引用版本3.0.0.0的原因)以及我该怎么做才能对其进行纠正?

推荐答案

我发现了这个问题,并认为这可能会对其他可能遇到相同问题的人有所帮助.

I figured out the issue and thought it might be helpful to others who might encounter the same problem.

当激活WCF服务时,该过程的一部分将使用Type.GetType(string)来获取代表服务合同实施的类型.因为Type.GetType(string)要求目标类型为:

When a WCF service is activated, part of the process uses Type.GetType(string) to obtain the type that represents the implementation of the service contract. Because Type.GetType(string) requires that the target type be either:

  • 在调用程序集中(在这种情况下,它将永远不会出现)
  • 在mscorlib中(同样,它将永远不会发生)
  • 完全用程序集限定的名称指定

除非使用使用程序集限定的名称指定类型,否则它将失败.

It will fail unless the type is specified using its assembly-qualified name.

由于这个原因(为了使仅使用名称空间限定的名称更容易指定服务类型),激活器将扫描所有引用的程序集并调用Assembly.GetType(string)(可以仅使用名称空间限定的名称),直到找到一个兼容类型.

Because of this (and to make specifying service types easier with just the namespace-qualified name), the activator will scan all referenced assemblies and call Assembly.GetType(string) (which can take just a namespace-qualified name) until it locates a compatible type.

虽然我无法解释4.0引用具体来自何处,但它一定已经存在于引用的程序集中.通过更改.svc文件中的ServiceHost标记以使我的服务使用程序集合格的名称,WCF成功加载了该服务.

While I can't explain where the 4.0 references were coming from specifically, it must have been in a referenced assembly. By altering the ServiceHost tag in the .svc file for my service to use the assembly-qualified name, WCF successfully loaded the service.

这篇关于WCF服务(IIS 7)中的莫名其妙程序集负载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆