5
votes

I got the following error while trying to add service reference to a ASP.NET MVC 5 web application in Visual Studio 2012. I already have a reference to Microsoft.Owin.Security version 3.0.0.0 in my project. Should I also add for the 2.0.1.0 version?

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.1.0.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='IMyService']

This guy here had a similar issue but no one answered..

2
I'm going to mark this as a duplicate, because as you said the other question is the exact same question. Recommend you place a bounty on the original question.Philip Pittle
@HélderGonçalves The only thing that worked for me was to work with my own authentication rather than Microsoft's I hope that a solution can be foundEnzero

2 Answers

10
votes

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

Reuse types selection

0
votes

I know this is an old question but I had the same issue trying to reference another service created by our company that uses some assemblies that needed to be reused for references purposes.

If you don't have the need to reuse assemblies, you should be just fine loading a service using the accepted answer.

But if you do need to reuse assemblies, I manage to fix this doing the following.

On Visual studio:

  • Remove the service
  • Clean the solution
  • Close Visual studio

In your project's folder:

  • Remove the packages folder
  • Remove the .vs (Visual studio generated folder)

In IIS (If you have access to it)

  • Recycle the application pool (I don't think it actually did anything but who knows)

Open Visual Studio and make sure that your common assemblies/packages are exactly the same version that is being used by the service that you want to reference.

Add a new Service reference and, in the advanced window, select the assemblies that need to be reused.

Click OK and pray.

Hopefully you service is added successfully like mine did after these steps.