Silverlight - failed to generate code for the service reference

When you add Service Reference into Silverlight project, some time you get “failed to generate code for the service reference…” error.  Which means Visual Studio is failed to generate client code, and if see “Reference.cs” file it is empty. This is the common error most of the people get.

There is work around to fix this issue. You may use below options for the same.

Option 1:

Use this option if your WCF service reference is not added into your project.

In “Add Service Reference” dialog click on “Advanced…” button. This will open Service Reference Settings dialog box.

 ServiceRef.jpg

In the Settings dialog box uncheck the “Reuse types in referenced assemblies” check box and click on Ok button.

 ServiceRefSettings.jpg 

Once you click on Ok button in Service Reference dialog box, the client code will be generated and you will not get any error. Now if you open “Reference.cs” file you can see the generated code.

Option 2:

Use this option if the service reference is already added into your project.

Right click on the service reference and select “Configure Service Reference…” option.


ConfigureSvc.jpg

This will open “Service Reference Settings” dialog box (see image #2 in Option 1). Now as I mentioned in Option #1, uncheck “Reuse types in referenced assemblies” and click on Ok button.

Right click on service reference and select “Update Service Reference”. Once the service reference is updated you can see the client code is generated, you may verify this in “Reference.cs” file.

 

Ebook Download
View all
Learn
View all