ClientSyncProvider InvalidCastException assigning to SyncAgent.LocalProvider

Lezárt ClientSyncProvider InvalidCastException assigning to SyncAgent.LocalProvider

  • Monday, 19 October, 2009 12:07 PM
     
     
    Hi,
    I'm already trying a few hours to get the SynCFramework exammple to work with SQL Server 2005.
    I changed the LocalProvider to this:

     

    Utility util = new Utility();

     

    SqlConnection clientConn = new SqlConnection(util.ClientConnString);

     

    this.LocalProvider = new SqlSyncProvider("main", clientConn);

    The ClientConnString is

     

    public string ClientConnString

    {

     

    get { return @"Data Source=" + _serverName + "; Initial Catalog=" + "ClientDB" +"; Integrated Security=True"; }

    }

     

    But I always get the error InvalidCastException.
    I checked the versions of my dlls and they all point to
    C:\Program Files\Microsoft SDKs\Microsoft Sync Framework\2.0\Runtime\ADO.NET\V3.0\x86\

    I installed the newest version of the MSF today but I had the same problem last week.

    It drives me really nuts, does anybody know how to get around this error?

    Thanks a lot!
    Daniel

    • Moved by Max Wang_Chinasoft Wednesday, 20 April, 2011 9:47 PM Forum consolidation (From:SyncFx - Technical Discussion [ReadOnly])
    •  

All Replies

  • Tuesday, 20 October, 2009 4:48 PM
     
     
    Hi,

    I've had the same thing after installing the newest version today.  As you it has driven me completely nuts because I had a working sample off the samples site and my code in my application wasn't working.  Everytime the localprovider property on the SyncAgent was set I got InvalidCastException

    However I managed to find the difference and sort the problem.  For me it was clearly an  assembly reference problem, within VS I changed "Specific Version" from True to False for each reference of

    Microsoft.Synchronization
    Microsoft.Synchronization.Data
    Microsoft.Synchronization.Data.Server
    Microsoft.Synchronization.Data.SqlServerCe

    Once this was done everything worked fine.  I didn't do anything special when adding the references only selected from the GAC.

    Hope that helps you.


    Tim
  • Wednesday, 21 October, 2009 8:56 AM
     
     
    Hi,

    thanks for your answer, but I'm afraid it didn't solve my issue.

    I checked all the version numbers of the DLLs (after setting the specific version to false) and they are

    Microsoft.Synchronization runtime version v2.0.50727 version 2.0.0.0
    Microsoft.Synchronization.Data runtime version v2.0.50727 version 3.0.0.0
    Microsoft.Synchronization.Data.Server runtime version v2.0.50727 version 3.0.0.0
    Microsoft.Synchronization.Data.SqlServer runtime version v2.0.50727 version 3.0.0.0

    I changed the example from SQLServerCE to SqlServer
    and the LocalProvider to this:

     

    Utility util = new Utility();

     

    SqlConnection clientConn = new SqlConnection(util.ClientConnString);

     

    this.LocalProvider = new SqlSyncProvider("main", clientConn)

    Can you see anything wrong with this?

    Thanks
    Daniel


    The stack trace of the error is this:

       at Microsoft.Synchronization.SyncAgent.set_LocalProvider(SyncProvider value)
       at Microsoft.Samples.Synchronization.SampleSyncAgent..ctor() in C:\Documents and Settings\dschmitz\My Documents\sync\MSyncF\MSyncF\Program.cs:line 73
       at Microsoft.Samples.Synchronization.Program.Main(String[] args) in C:\Documents and Settings\dschmitz\My Documents\sync\MSyncF\MSyncF\Program.cs: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()
  • Wednesday, 21 October, 2009 10:56 PM
    Answerer
     
     Answered
    Hi -

    You are using a new provider ( SqlSyncProvider) but assigning it to SyncAgent whcih accepts only the old hub-spoke providers. Use SyncOrchestrator instead of SyncAgent to do the synchronization.

    Thanks
    Deepa
    Deepa ( Microsoft Sync Framework)
  • Monday, 7 December, 2009 7:38 PM
     
     

    The problem with this is that SyncOrchestrator doesn't support multiple SyncTables (Configuration.SyncTables) like SyncAgent does. How do you accomplish the same with the SyncOrchestrator?