在为WCF服务生成类型时,.NET加载了寻找另一个版本的程序集

时间:2022-02-13 16:46:55

I got this error while trying to add service reference to my ASP.NET web application in Visual Studio 2013. I had reference to Microsoft.Owin.Security version 2.1.0.0 in my project. But I'm discouraged why he looking for 2.0.1.0 version?

尝试在Visual Studio 2013中向ASP.NET Web应用程序添加服务引用时出现此错误。我在项目中引用了Microsoft.Owin.Security版本2.1.0.0。但是我很沮丧他为什么要寻找2.0.1.0版本?

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.Owin.Security, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

无法导入wsdl:portType详细信息:运行WSDL导入扩展时抛出异常:System.ServiceModel.Description.DataContractSerializerMessageContractImporter错误:无法加载文件或程序集'Microsoft.Owin.Security,Version = 2.0.1.0,Culture = neutral, PublicKeyToken = 31bf3856ad364e35'或其依赖项之一。该系统找不到指定的文件。

2 个解决方案

#1


1  

I did find and post a possible solution on Hélder Gonçalves' version of this question. Hopefully it will allow you to generate the service reference without redirecting to an older version of the Microsoft.Owin.Security assembly. Please let me know if this works for you.

我找到并发布了关于HélderGonçalves这个问题版本的可能解决方案。希望它允许您生成服务引用,而无需重定向到较旧版本的Microsoft.Owin.Security程序集。如果这对你有用,请告诉我。

Per Rizier123 suggestion, here's the text from my solution in full:

根据Rizier123的建议,这里是我的解决方案中的文字:

Had the exact same error verbatim and was able to resolve it by specifying which assemblies to reuse types from.

有完全相同的错误逐字,并能够通过指定要重用类型的程序集来解决它。

When adding the service reference, click the Advanced... button in the bottom left corner of the Add Service Reference window. On the Service Reference Settings screen that appears, in the Data Type section, under the Reuse Types in all referenced assemblies: check-box, select the Reuse types in specified reference assemblies radio button then check ONLY the assemblies that contain types used by the service. This should resolve the issue.

添加服务引用时,单击“添加服务引用”窗口左下角的“高级...”按钮。在“服务引用设置”屏幕上,在“数据类型”部分的“所有引用的程序集中的重用类型:”复选框下,选中“在指定的引用程序集中重用类型”单选按钮,然后仅检查包含服务使用的类型的程序集。这应该可以解决问题。

#2


0  

The assembly versions that are actually installed and referred varies due to various factors. Anyway you can redirect the binding to your desired versions. Refers this link

实际安装和引用的组件版本因各种因素而异。无论如何,您可以将绑定重定向到所需的版本。参考此链接

In your case, you have to add the following lines to the web.config under configuration

在您的情况下,您必须将以下行添加到配置下的web.config

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="'Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
      <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.0.1.0"/>
    </dependentAssembly>
    </assemblyBinding>
</runtime>

#1


1  

I did find and post a possible solution on Hélder Gonçalves' version of this question. Hopefully it will allow you to generate the service reference without redirecting to an older version of the Microsoft.Owin.Security assembly. Please let me know if this works for you.

我找到并发布了关于HélderGonçalves这个问题版本的可能解决方案。希望它允许您生成服务引用,而无需重定向到较旧版本的Microsoft.Owin.Security程序集。如果这对你有用,请告诉我。

Per Rizier123 suggestion, here's the text from my solution in full:

根据Rizier123的建议,这里是我的解决方案中的文字:

Had the exact same error verbatim and was able to resolve it by specifying which assemblies to reuse types from.

有完全相同的错误逐字,并能够通过指定要重用类型的程序集来解决它。

When adding the service reference, click the Advanced... button in the bottom left corner of the Add Service Reference window. On the Service Reference Settings screen that appears, in the Data Type section, under the Reuse Types in all referenced assemblies: check-box, select the Reuse types in specified reference assemblies radio button then check ONLY the assemblies that contain types used by the service. This should resolve the issue.

添加服务引用时,单击“添加服务引用”窗口左下角的“高级...”按钮。在“服务引用设置”屏幕上,在“数据类型”部分的“所有引用的程序集中的重用类型:”复选框下,选中“在指定的引用程序集中重用类型”单选按钮,然后仅检查包含服务使用的类型的程序集。这应该可以解决问题。

#2


0  

The assembly versions that are actually installed and referred varies due to various factors. Anyway you can redirect the binding to your desired versions. Refers this link

实际安装和引用的组件版本因各种因素而异。无论如何,您可以将绑定重定向到所需的版本。参考此链接

In your case, you have to add the following lines to the web.config under configuration

在您的情况下,您必须将以下行添加到配置下的web.config

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="'Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
      <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.0.1.0"/>
    </dependentAssembly>
    </assemblyBinding>
</runtime>