WCF 服务中无法解释的程序集负载 (IIS 7)

发布于 2024-09-13 05:36:13 字数 3255 浏览 7 评论 0原文

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

无法加载文件或程序集“System.IdentityModel,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”或其依赖项之一。系统找不到指定的文件。

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

以下是 Web 应用程序 Web.config 中的 标记:

<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>

注意:后来添加了 标记作为故障排除尝试。它似乎对行为没有任何影响。我添加它是因为 IIS 配置管理器的“.NET Compilation”选项卡给我一个错误,指出 System.Data 被添加了两次,但显然不在这个文件中。添加 帮我解决了这个问题,但我在 Machine.config 中找不到有问题的重复项,并且没有基本网站 Web.config,所以我想知道是否有我没有注意到的地方可能是问题的原因。

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

有谁知道为什么它尝试加载此程序集(仅引用版本 3.0.0.0 时)以及我可以采取哪些措施来纠正它?

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.

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.

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.

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>

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.

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.

Does anyone know why it's attempting to load this assembly (when only version 3.0.0.0 is referenced) and what I can do to correct it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森林散布 2024-09-20 05:36:14

我弄清楚了这个问题,并认为这可能会对其他可能遇到同样问题的人有所帮助。

当激活 WCF 服务时,部分流程使用 Type.GetType(string) 来获取表示服务协定实现的类型。因为 Type.GetType(string) 要求目标类型是:

  • 在调用程序集中(在本例中,它永远不会是)
  • 在 mscorlib 中(同样,它永远不会是)
  • 完全使用程序集限定名称指定

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

因此(并且为了仅使用命名空间限定名称来更轻松地指定服务类型),激活器将扫描所有引用的程序集并调用 Assembly.GetType(string) (它可以只采用命名空间 -限定名称)直到找到兼容的类型。

虽然我无法具体解释 4.0 引用的来源,但它一定位于引用的程序集中。通过更改我的服务的 .svc 文件中的 ServiceHost 标记以使用程序集限定名称,WCF 成功加载了该服务。

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

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:

  • In the calling assembly (which, in this case, it would never be)
  • In mscorlib (again, which it would never be)
  • Fully specified with an assembly-qualified name

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

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文