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 from this blog

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

"$.ajax is not a function" Error When Using jQuery and Darren Johnstone's ASP.NET Upload/Download Module v2