Resolving a Problem When Adding A Reference to a WCF Service

Awhile ago, I was having issues adding a WCF service reference to a project I was working on. I was getting an error when trying to add the reference that said “Custom tool error: Failed to generate code for the service reference”. Looking at the Reference.cs file for the service, it was blank except for the comment block at the top.

The answer lied in one of the warning messages (I've changed some of the assembly and namespace names below to protect my company's privacy):

Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: List of referenced types contains more than one type with data contract name 'Content' in namespace ''. Need to exclude all but one of the following types. Only matching types can be valid references:
"MyCompany.BackOffice.Core.Domain.Packaging.RadAssembly.Accessors.Content, MyCompany.BackOffice.Core.Domain, Version=, Culture=neutral, PublicKeyToken=null" (matching)
"MyCompany.BackOffice.Core.Domain.Packaging.CreativeCollection.Entities.Content, MyCompany.BackOffice.Core.Domain, Version=, Culture=neutral, PublicKeyToken=null" (not matching)
XPath to Error Source: //wsdl:definitions[@targetNamespace='']/wsdl:portType[@name='IRadAssemblyDatabridge'] C:\Projects\BackOffice\BackOfficeServices\branches\RadProgramming\Adaptation\Orchestration\RAD\src\Adaptation.Orchestration.RAD.Infrastructure\Service References\RadAssemblyDatabridge\Reference.svcmap 1 1 Adaptation.Orchestration.RAD.Infrastructure

In other words, two classes in different namespaces but with the same name. The fix was to change this:

[DataContract(Namespace = "")]

To this:

[DataContract(Namespace = "", Name = "RadAssemblyContentAccessor")]

Hopefully this will save someone some time if they run across the same issue.


Popular Posts

How To Mock Out Child Components In Unit Tests of Angular 2 Code

A Generic Method Using HttpClient to Make a Synchronous Get Request

The Cause and Solution for the "System.Runtime.Serialization.InvalidDataContractException: Type 'System.Threading.Tasks.Task`1[YourTypeHere]' cannot be serialized." Exception

A Red Herring When Using Moq to Mock Methods With Optional Parameters

Unit Testing with a Mock Entity Framework DbContext and Fake DbSets