Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "Recursive collection data contract" when referencing a WCF service with a slightly complex method

If I use only simple methods in my WCF service, everything works fine. However, if I include the following method, a problem occurs:

[OperationContract]
public List<KeyValuePair<string, string>> GetAllAccounts()
{
    return AccountBusiness.GetAllAccounts();
}

I get this error when referencing the service from another project:

Warning 5 Custom tool warning: Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter Error: Type 'Newtonsoft.Json.Linq.JToken' is a recursive collection data contract which is not supported. Consider modifying the definition of collection 'Newtonsoft.Json.Linq.JToken' to remove references to itself. XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org']/wsdl:portType[@name='NodeService'] C:\inetpub\wwwroot\MyclientProject\Service References\NodeService\Reference.svcmap 1 1 MyClientNode

If I remove the method above, recompile and update the reference, then it works fine. But when I add the above method, I consistently get this warning.

One suggestion I found was to uninstall Visual Studio 2012 and repair Visual Studio 2010. I don't want to do that.

Another suggested to uncheck "Reuse types in all referenced assemblys", but this messes up the method signatures and is not usable.

like image 371
Niels Brinch Avatar asked Aug 22 '12 08:08

Niels Brinch


1 Answers

As it turned out, the error was caused by the fact that I had a Microsoft Web API package installed from NuGet, which included Json.NET. After uninstalling this, it works fine.

This may be the answer for you - if not, look at which other packages you have installed (that you don't need) and remove them.

like image 89
Niels Brinch Avatar answered Sep 30 '22 16:09

Niels Brinch