locked
SqlCeClientSyncProvider invalid cast in MS sample code RRS feed

  • Question

  • Hi

    I am trying to run the sample code form How to: Upload Incremental Data Changes to a Server found at

    http://msdn.microsoft.com/en-us/library/bb726033.aspx

    i have followed all the steps but when i run the application i get a System.InvalidCastException was unhandled. The full message is at the bottom.

    This is the line that throws the error
     

    Me.LocalProvider = New SampleClientSyncProvider()

    I have tried changing it to

    Me.LocalProvider = New SqlCeClientSyncProvider()

    i am using sql 2005 SP3, SQL compact 3.5 sp1 and VS 2008

    but still the same message i get this in both C# and VB.Net

    System.InvalidCastException was unhandled
      Message="Microsoft.Synchronization.Data.ClientSyncProvider"
      Source="Microsoft.Synchronization.Data"
      StackTrace:
           at Microsoft.Synchronization.SyncAgent.set_LocalProvider(SyncProvider value)
           at ConsoleSyncToServerVB.SampleSyncAgent..ctor() in C:\Documents and Settings\akhoddam\My Documents\Visual Studio 2008\Projects\ConsoleSyncToServerVB\ConsoleSyncToServerVB\Program.vb:line 70
           at ConsoleSyncToServerVB.Program.Main(String[] args) in C:\Documents and Settings\akhoddam\My Documents\Visual Studio 2008\Projects\ConsoleSyncToServerVB\ConsoleSyncToServerVB\Program.vb:line 38
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException:


    Thanks

     

    • Moved by Hengzhe Li Friday, April 22, 2011 2:49 AM (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Monday, July 13, 2009 9:57 PM

Answers

  • Add this to the app.config should fix the problem

    <?xml version="1.0"?>

    <configuration>

          <runtime>

                <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

                      <dependentAssembly>

                            <assemblyIdentity name="Microsoft.Synchronization.Data" publicKeyToken="89845DCD8080CC91" culture="neutral"/>

                            <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>

                      </dependentAssembly>

                </assemblyBinding>

          </runtime>

    </configuration>

     

     

    Tuesday, July 14, 2009 6:30 PM