Unity 3.0和DataContractSerializerMessageContractImporter

时间:2014-02-25 12:13:50

标签: c# wcf visual-studio-2013 unity-container prism

我尝试在Visual Studio 2013中向我的类库项目添加一个新的服务引用

但是在生成代码之前,VS.NET抛出了这个:

Warning 2   Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Could not load file or assembly 'Microsoft.Practices.Unity, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='IWcfXXXService'] c:\Projects\...\Service References\ServiceReference1\Reference.svcmap   1   1   Domain.XXX

我正在使用Prism 4.1,所以Unity 3.0是必须的,它运行正常 - 除了生成服务引用。我真的很困惑: Unity DataContractSerializerMessageMontractImporter 中常见的是什么?

如果我删除了Prism.UnityExtension,那么一切正常。

我该怎么办?我不希望在每次服务引用刷新时将Unity 3.0更改为2.1.505.0。

1 个答案:

答案 0 :(得分:1)

Prism 4.1是针对Unity 2.1.505.0构建的,Unity的程序集与Prism 4.1一起发布

如果您真的想使用Unity 3.0并且您不想更改程序集引用,那么您可以使用程序集重定向来强制在请求Unity 2.1时加载Unity 3.0

将以下内容添加到应用程序的配置文件中。

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.Practices.Unity"
                        publicKeyToken="31bf3856ad364e35"
                       />
      <!-- Assembly versions can be redirected in application, publisher policy, or machine configuration files. -->
      <bindingRedirect oldVersion="2.1.505.0"
                       newVersion="3.0.1304.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.Practices.Unity.Interception"
                        publicKeyToken="31bf3856ad364e35"
                       />
      <!-- Assembly versions can be redirected in application, publisher policy, or machine configuration files. -->
      <bindingRedirect oldVersion="2.1.505.0"
                       newVersion="3.0.1304.0"/>
    </dependentAssembly>
  </assemblyBinding>
</runtime>