The other day I refreshed one of our WCF services (right click the service and do a Update Service Reference) and all of a sudden I got a metric crap-ton of build errors. In each place I received the error it told me that the type was not found. At first I could not understand what was going on, in fact I was sure the compiler was playing tricks on me (cause we all the compiler has a devilish sense of humor) because how could it be possible that all of my types went missing.
Just to be sure I took a look at the generated code in the Reference.cs class and sure enough all my types were missing.
Now that I know the compiler is not just playing tricks on me it was time to find out what happened.
The first thing I did was to try recompiling the service and updating my references again, but as you could have guessed this did not solve my problem. Next I decided to try to create a duplicate reference to the service to see if maybe my original reference was screwed up, and as you may have guess the new reference also was missing my types (shocking I know). At this point I was a bit stumped, and did not know exactly what could have caused the issue. I next decided to take a look at the service configuration so I right clicked on the service and selected ‘Configure Service Reference’. When I did this the screen below appeared
After looking at this for a few minutes it dawned on me what had happened. The check box (one circled in red) was selected (and is by default) and someone on the team had added direct reference to the assembly which contained my Models that were provided via the web service. I decided to uncheck that check box and give that a whirl and sure enough my Models came pack. Now that I was back up and running, it was time to remove the direct reference from my project to the assembly which hosts my WCF service as there is no point in both referring to it locally as well as hitting it via a service.
Long story short, if you refresh your WCF reference and all your Data Contract Models disappear there are 2 things you need to look for.
- Are you referencing the service assembly locally (if so why?)
- Do you have the ‘reuse types’ check box selected in the WCF configuration screen?
If either (or both) of the above are set then you should have your solution.
Till next time,
02-09-2010 5:28 AM