Silverlight 3 Tools Issue: New WCF Template is Broken by Silverlight 2 SDK

In Silverlight 3, we’ve introduced support for binary message encoding for WCF services, which should give a performance boost.  Silverlight 2, as you may recall, only supports basicHttpBinding.  The new binding is the default for Silverlight-enabled WCF services created with the Silverlight 3 Tools.

If you’ve upgraded from the Silverlight 2 Tools for Visual Studio to the Silverlight 3 Tools for Visual Studio, you may run into the following warnings when adding a reference to a newly created WCF service (i.e. using the new template in Silverlight 3 Tools):



If you continue to run your Silverlight application, it will throw an exception when you try to instantiate a client for your service.  The stack trace will look like the following:

The given key was not present in the dictionary.

at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at System.ServiceModel.Configuration.ServiceModelSectionGroup.get_Client()
at System.ServiceModel.Description.ConfigLoader.LookupChannel(String configurationName, String contractName, Boolean wildcard)
at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)
at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName)
at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory()
at System.ServiceModel.EndpointTrait`1.CreateChannelFactory()
at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
at System.ServiceModel.ClientBase`1..ctor()
at Somewhere.In.Your.Silverlight.Application()

This is caused by a bug where the Microsoft.Silverlight.ServiceReference.dll assembly is loaded into VS from the Silverlight 2 SDK instead of the Silverlight 3 SDK.  Since Silverlight 3 adds support for binary encoding in WCF services, when you add a service reference to such a service using the Silverlight 2 assembly it fails and the generated ServiceReferences.ClientConfig is non-functional.

To work around this issue for now, uninstall the Silverlight 2 SDK, update your service reference, and rebuild your Silverlight application.

If you want your service to be consumable by both Silverlight 2 and Silverlight 3 applications, you can change the binding back to basicHttpBinding.  To do that, edit the web.config file for the web project containing the service.  Then update the service reference and rebuild your Silverlight application.

Comments (13)

  1. With the release of Silverlight 3 Beta, you’ll may want to try out the new features. Unfortunately, Silverlight

  2. Gary says:

    I saw this warning. Do you know why?

    Warning 1 The element cannot contain white space. Content model is empty. D:AzureSilverlightApplication1SilverlightApplication1ServiceReferences.ClientConfig 7 99 SilverlightApplication1

    Warning 2 The element ‘httpTransport’ cannot contain child element ‘extendedProtectionPolicy’ because the parent element’s content model is empty. D:AzureSilverlightApplication1SilverlightApplication1ServiceReferences.ClientConfig 8 26 SilverlightApplication1





    <binding name="CustomBinding_Service1">

    <binaryMessageEncoding />

    <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">

    <extendedProtectionPolicy policyEnforcement="Never" />






    <endpoint address="http://localhost:63165/Service1.svc&quot; binding="customBinding"

    bindingConfiguration="CustomBinding_Service1" contract="ServiceReference1.Service1"

    name="CustomBinding_Service1" />




  3. Jimmy Lewis says:

    Gary, I think it’s due to the section:

    <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">

      <extendedProtectionPolicy policyEnforcement="Never" />


    Can you try removing the <extendedProtectionPolicy> element and making the <httpTransport> element self-closing?  I haven’t figured out what causes this to be generated incorrectly yet.

  4. Gary says:

    It works. Thank you very much for help.

  5. AP says:

    Thank you very much for this post. I spend 10hr on a single problem (i never spent this much time on a single issue to solve) and I was stuck where no matter what i do i get "The remote server returned an error: NotFound" WebException. After reading your post i uninstall silverlight 2.0 sdk then remove and added the WCF service back and the error went away and project is working fine.

  6. vitthalgb says:

    i have removed SL 2 SDK.But my app not showing the output.

    whatever i am returning from service is not collecting into the SL app.

    my code is as follows–>


    Imports System.ServiceModel

    Imports System.ServiceModel.Activation

    <ServiceContract(Namespace:="")> _

    <AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _

    Public Class Service1

       <OperationContract()> _

       Public Function DoWork()

           Dim db As EMPDataClassesDataContext = New EMPDataClassesDataContext()

           Return db.EMPs.Where(Function(emp) emp.EMPSAL > 0)

           ‘ Add your operation implementation here

       End Function

       ‘ Add more operations here and mark them with <OperationContract()>

    End Class


    Imports WebServiceApp.ServiceReference1

    Partial Public Class MainPage

       Inherits UserControl

       Public Sub New()


           Dim proxy As ServiceReference1.Service1Client = New ServiceReference1.Service1Client()

           AddHandler proxy.DoWorkCompleted, AddressOf proxy_DoWorkCompleted



       End Sub

       Private Sub proxy_DoWorkCompleted(ByVal sender As Object, ByVal e As ServiceReference1.DoWorkCompletedEventArgs)

           grdEmp.ItemsSource = e.Result

       End Sub

    End Class

    but when iam debugging the code the proxy_DoWorkCompleted Method is not there is no chance to obtain returned result from what could be the problem?

    please help me.

    Thanks in advance.

  7. Rik says:

    I’m having this same issue, but I am on an install that has never had any SL2 installed.  

  8. Ben says:

    have the same problem, uninstall of sdk 2, rebuild and re-reference does not fix it. I think the problem is caused by my ServiceReferences.ClientConfig being (almost) empty, it only contains: "<configuration/>"

    That problem is discussed here:

    of the three solutions given, 2 of them dont work and the third one is difficult (filling it manually) if you dont know what the content should be (I am still learning)

  9. Ultraviolet says:

    I’m only building styles using SL3 and I’m having this error. It doesn’t keep my styles from working, but it’s keeping me from adding new styles to the DictionnaryRessource file saying that something’s wrong with my styles.

    This is driving me nuts !

  10. Ultraviolet says:

    SL2 was never installed on my machine before.

  11. cheung says:

    Hello, i am the same problem…

    I don’t havec SL 2 SDK only SL 3 SDK.

    Before it was ok, but even to edit manually the file ServiceReferences.ClientConfig the problem appears and i cant test my wcf services…

  12. vinay says:

    Has anybody found a solution? I'm on SL4 and Visual Studio 2010. I keep getting the same error:

    My client config seems fine; the web service shows up in IE;

      at System.ThrowHelper.ThrowKeyNotFoundException()

      at System.Collections.Generic.Dictionary`2.get_Item(TKey key)

      at System.ServiceModel.Configuration.ServiceModelSectionGroup.get_Client()

      at System.ServiceModel.Description.ConfigLoader.LookupChannel(String configurationName, String contractName, Boolean wildcard)………………….