Reference.svcmap: 无法加载文件或程序集 Microsoft.Practices.ServiceLocation,版本号为1.0.0.0。

6

我有一个简单的Webforms网站项目。该项目使用通过NuGet添加的Microsoft Application Block Unity 3.5(DI容器)。

现在我正在使用第三方Web服务。当我添加服务引用并构建后,出现以下情况:

Error 19 Reference.svcmap: Could not load file or assembly 'Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) App_WebReferences/MyExternalService/

因此,我安装了Microsoft.Practices.ServiceLocation,但它仍然抱怨该程序集。

enter image description here

我尝试将以下内容添加到web.config文件中,但仍无法解决。

 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Practices.ServiceLocation" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>

一旦我卸载Unity包,一切都好了。没有错误,我可以使用服务代理。

尝试过Clean Build等方法,但仍然无法解决。

有什么想法吗?

1个回答

12

我安装了错误的包以获取对 Microsoft.Practices.ServiceLocation 的引用。

错误的包: 图片描述

正确的包是: 图片描述


软件包管理器难道不应该处理这个依赖关系吗?我遇到了同样的问题。 - Christian Rodriguez
@ChristianRodriguez 我认为 Web 服务代理类需要那个引用。Unity 本身不需要那个包。 - gbs
1
@gbs:可能有点晚了,但我想告诉你,在经历了两天以上的折磨后,你救了我。谢谢! - Flame_Phoenix

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接