我在 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.
最佳答案
我确实在 Hélder Gonçalves' version of this question. 上找到并发布了一个可能的解决方案希望它允许您生成服务引用,而无需重定向到旧版本的 Microsoft.Owin.Security 程序集。如果这对您有用,请告诉我。
根据 Rizier123 的建议,这是我的解决方案的完整文本:
逐字出现完全相同的错误,并且能够通过指定要重用哪些程序集的类型来解决它。
添加服务引用时,单击添加服务引用窗口左下角的高级...按钮。在出现的 Service Reference Settings 屏幕上,在 Data Type 部分的 Reuse Types in all referenced assemblies: 复选框下,选择Reuse types in specified reference assemblies 单选按钮,然后仅选中包含服务使用的类型的程序集。这应该可以解决问题。
关于c# - .NET 在为 WCF 服务生成类型时加载寻找另一个版本的程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22985704/