7
votes

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?

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.

2
Same thing happening to me... Any conclusions?Hélder Gonçalves
Have you checked your project file? It's likely just a bug in the Nuget Package from that specific OWIN package. It probably put the wrong version # in your project file, but the right assembly in your references.user817530
Hi, I have the same issue. I checked my project file : the references are the good ones. Does somebody have any clues ?Sam
I found that when I change from "reuse types in all referenced assemblies" to "reuse types in specified reference assemblies" and check only the assembly containing my datacontracts it's working. Maybe there is some cache but I was not able to find it (I deleted all the bin/obj directories, rebooted the computer, ... and still had the issue)Sam

2 Answers

1
votes

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.

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

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.

0
votes

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

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