Silverlight: Update service reference for a WCF service generating empty class

My Visual Studio sometimes goes angry. I had a Silverlight 2 – WCF – LINQToSQL application that I recently converted to Silverlight 3. I noticed that sometimes the Update Service Reference does not function properly and instead blanks out the generated reference.cs. It broke once again today and I decided to blog it. Here are the contents of Error window when such abnormal activity happens:

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

The warning tab may have many warnings, some of which are:

Custom tool warning: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Custom tool warning: The type 'System.Collections.ObjectModel.ObservableCollection`1' could not be found.  Ensure that the assembly containing the type is referenced.  If the assembly is part of the current development project, ensure that the project has been built.

Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Exception has been thrown by the target of an invocation.
XPath to Error Source: //wsdl:definitions[@targetNamespace='']/wsdl:portType[@name=..]

Custom tool warning: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='..']/wsdl:binding[@name='..']

Custom tool warning: No endpoints compatible with Silverlight 3 were found. The generated client class will not be usable unless endpoint information is provided via the constructor.

Ok. Looks like something is wrong with the Observable Collection reference. This was further confirmed when I brought up the service configuration window (by right clicking the WCF service and selecting Configure Service Reference), and noticed that the ObservableCollection collection type has been replaced by { Custom } :

service-reference-incorrect

For comparison, here’s the normal screenshot for this window:

service-reference-correct

To get rid of this and regenerate service proxy properly, I had to remove the Reuse types in all referenced assemblies (or at least System assembly).

So, if such behavior ever happen to you, try to update the service reference after unchecking the reuse types checkbox. Once done, you can recheck the option and update your service reference again.

6 Responses to “Silverlight: Update service reference for a WCF service generating empty class”

  1. DotNetShoutout Says:

    Silverlight: Update service reference for a WCF service generting empty class « Mehroz’s Experiments…

    Thank you for submitting this cool story – Trackback from DotNetShoutout…

  2. DotNetBurner - Silverlight Says:

    Silverlight: Update service reference for a WCF service generting empty class « Mehroz’s Experiments…

    DotNetBurner – burning hot .NET content…

  3. FretNoize Says:

    Here is what helped me:

    http://blogs.infosupport.com/blogs/raimondb/archive/2008/02/14/Unable-to-generate-a-WCF-proxy-using-svcutil-but-retreiving-the-wsdl-works_3F00_.aspx

    Basically, give write rights to C:\Windows\Temp to the user under which the AppPool runs (or, to be sure this error does not happen again, give everybody write rights…)

  4. Syed Mehroz Alam Says:

    That’s a great find, FretNoize. I will verify this and update my post once I get the error again.

  5. Sankar Says:

    I am getting this error also
    The given key was not present in the dictionary.
    And two warning
    Warning 1 Custom tool warning: Endpoint ‘WSHttpBinding_IService1′ at address

    ‘http://localhost:1787/Service1.svc’ is not compatible with Silverlight 3. Skipping…

    D:\SilverlightProjects\SilverlightDemo\SilverlightDemo\Service

    References\ServiceReference1\Reference.svcmap

    Warning 2 Custom tool warning: No endpoints compatible with Silverlight 3 were found.

    The generated client class will not be usable unless endpoint information is provided via

    the constructor.

  6. Syed Mehroz Alam Says:

    Hi Sankar,

    Are you using wsHttpBinding for your service? I believe it isn’t supported for Silverlight yet. You may need to tweak your web.config to use basicHttpBinding or a custom binary binding. Have a look at this post: http://johnpapa.net/silverlight/wcf-binary-bindings-in-silverlight-3/


Leave a Reply