Tuesday, 24 February 2009

Creating Service Reference: Failed to generate code for the service reference

I was working on Windows Service that was consuming another WCF Windows Service. I created a Service Reference in Visual Studio 2008 and noticed that client code was not automatically generating. The error I was getting was

Error 4 Custom tool error: Failed to generate code for the service reference 'MyWindowsService'. Please check other error and warning messages for details.

The Windows Service I was working on was already full blown project with lots of references, so to limit possibilities I created another empty windows service and added Service Reference to one I need. Client code was generated with no problems! I decided to use new Windows Service as a base and added all required functionality to it and selected “Update Service Reference” and again it failed to generate a code!

image

After some time looking around there was an easy solution to fix a problem. You need to edit Service Reference Configuration by selecting “Configure Service Reference…” from right click menu.

image

In the dialog box Un-tick “Reuse types in referenced assembles” and click OK. Try to Update Service Reference. This worked for me!

References

.NET C# Broken WCF service reference in VS 2008

73 comments:

  1. Nice! Thanks! You saved me!

    ReplyDelete
  2. saved me too! I spent WAY too long on this
    thank-you

    ReplyDelete
  3. Thanks! I got this error when I started using compression (http://dimebrain.com/2008/06/compression-i-1.html). Had no idea that it was related until I read this page.

    ReplyDelete
  4. Thanks! I would never have found this one...

    ReplyDelete
  5. Any idea what that option (Reuse types) is for?

    ReplyDelete
  6. Thank you! Developing a demonstration with Telerik Drag and Drop Silverlight Control, which communicates with an SQL Server database, and required a web service.

    ReplyDelete
  7. Reuse Types need to be ticked to define classes in referenced DLLs that should not be generated, but reused from their definitions.

    ReplyDelete
  8. Thanks!! It was driving me crazy!

    ReplyDelete
  9. My thanks as well! Wow.

    Dave

    ReplyDelete
  10. Thank you!! That saves me!

    ReplyDelete
  11. Wsdl not updating problem fixed nicely. Very well done sir, you've saved my hair.

    ReplyDelete
  12. Thank a lol for this solution.

    ReplyDelete
  13. It worked!! Thank you. I wonder why it worked before with that option checked, but not anymore. Can anyone explain?

    ReplyDelete
  14. Not good when I need to reference the types. This was working until yesterday, then I added a generic property to a web service, obviously this refused to be run-time serialized (although it would compile fine). Removing this property and rebuilding everything several times and still it wont generate the reference.cs. Why is this so much hassle? Where is the feedback from the Microsoft tools? Their usability is shockingly poor.

    ReplyDelete
  15. thanx a million!

    ReplyDelete
  16. I can't believe Microsoft left it ticked as default, what a bugger! Annoying!!!!!

    My thanks to this post as well.

    ReplyDelete
  17. Oh man, you rock. Super quick fix!

    ReplyDelete
  18. Thank you, I was losing my mind

    ReplyDelete
  19. This is not a solution!

    ReplyDelete
  20. thanks man, awesome, fixed straight away, LEGEND.....

    ReplyDelete
  21. Thank you!!! Thank you!!! Thank you!!!

    ReplyDelete
  22. Thanks a lot....That worked like a charm :)

    ReplyDelete
  23. Thanks very much!! Saved my day!!

    ReplyDelete
  24. Brilliant, Thank you.

    ReplyDelete
  25. This was very helpful. Typically the re-use works. I need to use re-use but select specific types. This is necessary due to the multiple services sharing the same references.

    ReplyDelete
  26. absolutely brilliant.. thanks a lot.

    ReplyDelete
  27. Thanksssssssssss so mucccccccccchhhhhhhhhh

    ReplyDelete
  28. As just said on March 19th, 2010: this is not a solution.
    PM&LV

    ReplyDelete
  29. Good Stuff... Life saver

    ReplyDelete
  30. Good one. This one helped me. Thank you...

    ReplyDelete
  31. Thank you so much!! Saved me big time.

    ReplyDelete
  32. Thanks. I spent a lot of time on this.

    ReplyDelete
  33. I had the same problem. When I unchecked "Reuse..." it worked. When I later checked it again it still worked.

    ReplyDelete
  34. Awesome! Thanks - Saved me a lot of time

    ReplyDelete
  35. Thanks, saved me a bunch of time!

    ReplyDelete
  36. omg... thank you soooooooooooooo much!!!
    thank you, thank you, thank you!!!!!

    ReplyDelete
  37. -worships-

    I was doing the exact opposite. It didn't occur to me do un-tick the box. I'm an idiot. You're not. Thanks :)!

    ReplyDelete
  38. thanks!.. u saved me..

    ReplyDelete
  39. Thanks a lot!! really helped in saving so much time...!!!

    ReplyDelete
  40. ... IT WORKED ... !

    ReplyDelete
  41. Doesn't help me. I need those types. And it has worked for me before. This is ridiculous and one of the reasons why I am groing to despise microsoft's development environment

    ReplyDelete
  42. so easy but it takes me so many hours
    Thank you

    ReplyDelete
  43. FTW Man FTW - you are the best! Like everyone else said - saved me!

    ReplyDelete
  44. Nice Clue Buddy.

    ReplyDelete
  45. Same issue in VS2010. Thanks for posting your solution.

    ReplyDelete
  46. Wow, thank you.

    ReplyDelete
  47. 2 days of headache, very thanks, is that!!! solved.

    Gláucio.

    ReplyDelete
  48. Post is 3 years old and helped me with VS 2012!

    ReplyDelete
  49. This appears to be the tip that keeps on giving! Thanks much!!!

    ReplyDelete
  50. Thanks so much!

    ReplyDelete
  51. Wow... can't believe how many people had this problem... Thanks man!

    ReplyDelete
  52. It blows my mind how many people have had this issue and not figured out what the real root of the issue was.

    most of you will have 3 projects, a common, a webservice and a app that consumes the webservice. both the webservice and the app will have the common's assembly referenced.

    Now unchecking the reuse types only works because you are bypassing the real fault, which is you have made a change to the common assembly and either the webservice or the app has not got the latest version, so when you update the service reference there is a mismatch and the service reference cannot properly refresh.

    Simply clean all 3 projects, manually inspect each project's bin folders to ensure the common assembly is gone and in the case of a webservice running in a test vs/iis process kill that process and start it again.

    Your problem will be resolved.

    ReplyDelete
    Replies
    1. Dude you are a lifesaver. It took me a day to find this and it's such an easy problem to solve. Thank you!

      Delete
  53. Still works, helped me today!

    ReplyDelete
  54. Thanks!! You help me a lot!!

    ReplyDelete
  55. I don't mean to be the guy who doens't fit in here, but this post did not help me. The magic checkbox didn't work. However, I was able to get it to work by following Xavier's advice (three comments up). Thanks Xavier!

    ReplyDelete
  56. Thanks for sharing this information about us. Your blog is well perform. Visit website "Service Software Australia".

    ReplyDelete
  57. Thank you
    Life saver

    ReplyDelete
  58. Thank you so much! This was really helpful!

    ReplyDelete
  59. Thanks a lot...

    ReplyDelete
  60. Thank you, respect.

    ReplyDelete
  61. Fantastic Lovely ..............I Love You...........It's 3.23 Am

    I Helped my eye ...........................................................

    Lovely Carrie the fantastic service.............

    ReplyDelete
  62. Chuck Noris spent three hours on this and could not find a solution! THANKS!

    ReplyDelete