Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET loading wrong assembly when generating service reference

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

like image 653
Hélder Gonçalves Avatar asked Nov 05 '14 16:11

Hélder Gonçalves


People also ask

Why generate reference assemblies for your libraries?

Generating reference assemblies for your libraries can be useful when your library consumers need to build their programs against many different versions of the library. Distributing implementation assemblies for all these versions might be impractical because of their large size.

How to change an assembly reference during F# project build?

During F# project build, an assembly reference could be changed to a wrong version of the same assembly from Reference Assemblies. Create a new F# console app project targeting .NET 4.6.1. Install System.Net.Http NuGet package version 4.3.2. Note that it contains System.Net.Http.dll with assembly version 4.1.1.1. Build the project.

How to generate reference assemblies in MSBuild?

You can generate reference assemblies: In an MSBuild project, by using the ProduceReferenceAssembly project property. When compiling program from command line, by specifying -refonly ( C# / Visual Basic ) or -refout ( C# / Visual Basic) compiler options.

How to load an assembly from a specific version of Assembly?

If the handler knows the location of a version of the assembly, it can load the assembly by using the Assembly.LoadFrom or Assembly.LoadFile method, and can return the loaded assembly if successful.


1 Answers

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

like image 92
Nick Avatar answered Sep 18 '22 22:09

Nick