Menu Close

Custom Tool Error when updating service reference in VS 2010[Solved]

Day as usual, I was assigned some task to do in project, that I am working on. To meet the requirement I had to update service reference to one of WCF web-services included in solution. This was nothing new, service was in this solution almost from the start of the project, even before I got to work on it, being one of it’s central parts. I was really surprised, when operation, that I’ve completed many times before failed with error:

Error    27    Custom tool error: Failed to generate code for the service reference ‘<<serviceName>>’. Please check other error and warning messages for details.

After looking through the warnings I’ve found that three of them seemed to be the causes of this error. They looked something like this:

Custom tool warning: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
<some more info, some XPaths>

and alike for “port” and “portType”. I’ve looked at Reference.cs – there was no code inside, only some generated, commented out header.

That’s a bummer! After googling I’ve found that most popular solutions were:

  • remove reference, restart VS, add it from scratch
  • try restarting machine
  • check “Reuse types from referenced assemblies”
  • if you have installed VS2012 uninstall it reinstall VS2010

First and second one did not work. Third one was no good solution. Well, it made service reference to update, but in project referencing it I had all types doubled, so ambiguous types references all over the place. Fourth solution did not help.

Ok.. that’s easy – I thought – someone checked something in, that made this to happened. I just need to find a changeset, maybe check-in message will tell me something. If not maybe I can talk to author and He/She remembers what was changed. Searching of “guilty” changeset failed, previous versions had the same issue. In act of despair I got version from few month ago from repository. Same error. This indicates, that whatever caused this is “environmental”. But other team members can also reproduce this problem…

To find heart of the problem I’ve done so many different things to solution/web-references/assemblies-references, that I can not even remember all of them. What I ended up with was new solution with all new console application, WCF web-service application, and resources project from original solution. Console application could add/update service reference as long as WCF project had no reference to project from original solution. This indicated that problem is in resources project… but how? All it contains is resource file. I removed this file – it worked. I undid deleting it – it stopped to work. Then I just cleared the file – it worked, then added some content – it did not work again. Adding the content piece by piece caused service reference update not to work randomly. I had no clue what could cause such bazaar behavior.

Then, almost accidentally, inspired by some link, that my college sent me, I’ve used Bing to search for one of phrases, that I used previously in Google. At first page of Bing’s result I’ve found this: http://connect.microsoft.com/VisualStudio/feedback/details/534667/update-service-references-removes-all-content-from-reference-cs-file

Some MS guy says that it may have something to do with mscorlib or version of framework. In solution, that problem occurred, all projects use .NET 4.0, not reusing mscorlib types (seems like a stupid idea) did not work either.

Then, mentally exhausted after long struggle, I once again tried to get someone’s else’s attention to this problem. The same guy, that give me link, that led me to Bing figured out the cause of the problem. It turned out that what was causing it was reference to log4net, which was built with framework version 3.5. I’ve built log4net (using some Google-provided help, like for example http://stackoverflow.com/questions/1866735/log4net-and-net-4-0) using .NET Framework 4.0 and updated referenced assembly with fresh dlls. Problem magically disappeared.

I never knew what set this problem off. Log4net was in this solution for a long time. There must have been something, but I ceased to look for an answer, since main obstacle was solved and we were behind the schedule because of this problem.

Well.. I got two lessons learned:

  • When using WCF web-services, and updating/adding service reference is not working make sure that all your references were built against the same version of .Net Framework.
  • Vary your source of information. Google seems to me almost like a synonymous for “I’m looking for… “. As this case has shown sometimes it’s really helpful to break this mental habit.

Leave a Reply

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

*