WCF Custom tool error: Failed to generate code for the service reference.

Very recently, building multi-tier application involving Silverlight front-end inter-operating with WCF back-end, I encountered very odd, yet annoying behaviour of Visual Studio 2010. I was building new functionality using Telerik RadMap for Silverlight control that was to display some spartial data supplied by WCF service. To achieve this my Silverlight application had to reference few Telerik assemblies (Telerik.Windows.Controls.DataVisualization.dll). What is important is fact, that Service Reference for WCF service had been there already, project built and everything was working nicely, until I added extra method to WCF. After using “Update Service Reference” VS command, I started getting following error.

WCF error Screenshot no.1

Lack of further details with regards to this error and appropriate feedback from Visual Studio certainly does not help to get to the bottom of the problem, however after some investigation it turned out that one of Telerik assemblies caused this problem. When VS2010 creates service reference, default settings are that it should “reuse” all available types in reference. Excluding certain types from serialization allows service reference to be added successfully.

WCF error screen 2

I hope this helps anybody who got stuck with this problem.

20 thoughts on “WCF Custom tool error: Failed to generate code for the service reference.”

  1. That didnt work for me.
    I do not use the Telerik.Windows.Controls.DataVisualization dll and get the error.
    Are there other solutions?

    1. This can happen with other assemblies. I ran into this problem when upgrading from framework 4.0 to 4.5/

  2. This also happened for the Newtonsoft.JSON assembly. There should be a warning in the error list that tells you which assembly is causing the issue

  3. Beware about the dlls versions too.
    I’ve lost many hours until guess the SharpArch dll version in the client was different of the version in the WCF Service.
    Excluding this assembly from reuse, everything runs good.
    Thanks for help!

  4. Thank you so much Matt.
    But a question here is why this time I get this error? Im always using Telerik controls. How did you know the problem is Telerik.Windows.Controls.DataVisualization.dll

  5. Thanks for this useful article.

    In my case, i have this issue with my WPF project in VS.Net 2008. After going through this article, i was realizing that the assembly used in the web service is different version of assembly used on client.

    It works just fine after update assembly on the client.

  6. that didn’t work for me .
    i m having visual studio 2013 and 4.5
    i m unable to get Telerik.Windows.Controls.DataVisualization and i have unchecked Newtonsoft.JSON also but it is not working for me

    please help me on this

  7. i think you need
    Right click on your service reference and choose Configure Service Reference
    Then uncheck Reuse types in referenced assemblies
    Click OK, clean and rebuild your solution

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.