locked
File sync over WCF issue - reuse FileSyncProvider instance causes exception RRS feed

  • Question

  • I am doing a file synchronization over WCF.  If I do a download  on its own, it works. If I do an upload on its own, it also works.  If I do a download, make a change, and then do an upload using the same providers I used when doing the download, I get an InvalidCastException from CreateSyncSession.  If I create a new FileSyncProvider instance for the upload then it works.  Am I not allowed to re-use a FileSyncProvider instance or is there something else I need to clear?  The call stack for the exception is 

     

     

       at Microsoft.Synchronization.CoreInterop.SyncServicesClass.CreateSyncSession(ISyncProvider pDestinationProvider, ISyncProvider pSourceProvider)

       at Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWaySyncHelper(SyncIdFormatGroup sourceIdFormats, SyncIdFormatGroup destinationIdFormats, KnowledgeSyncProviderConfiguration destinationConfiguration, SyncCallbacks DestinationCallbacks, ISyncProvider sourceProxy, ISyncProvider destinationProxy, ChangeDataAdapter callbackChangeDataAdapter, SyncDataConverter conflictDataConverter, Int32& changesApplied, Int32& changesFailed)

       at Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWayKnowledgeSync(SyncDataConverter sourceConverter, SyncDataConverter destinationConverter, SyncProvider sourceProvider, SyncProvider destinationProvider, Int32& changesApplied, Int32& changesFailed)

       at Microsoft.Synchronization.KnowledgeSyncOrchestrator.Synchronize()

       at Microsoft.Synchronization.SyncOrchestrator.Synchronize()

       at SyncApplication.SynchronizationHelper.SynchronizeConfigFile(Int32 direction, String cfgFilePath, String cfgFile, String relativeDirOnServer, String& error) in c:\SynchronizationHelper.cs:line 678

     

    Wednesday, July 7, 2010 2:26 PM

All replies

  • Hi wicamnca

    You are allowed to reuse the same FileSyncProvider instance for future syncs.   Could you copy the piece of code from SynchronizeConfigFile that triggers the InvalidCastException?  What is the order of sync passed to the SyncOrchestrator?

     

     


    Maria del Mar Alvarez Rohena Microsoft Sync Framework
    Wednesday, July 7, 2010 9:15 PM
  • Here is the SynchronizeConfigFile routine. The providers are defined as static members of the class. The exception is coming from the Synchronize call.

     

     

           public int SynchronizeConfigFile(int direction, String cfgFilePath, String cfgFile, String relativeDirOnServer, out String error)

            {

                error = String.Empty;

                try

                {

                    if (localFileProvider == null)

                    {

                        List<string> includeList = new List<string>(2);

                        includeList.Add(cfgFile + ".dat");

                        includeList.Add(cfgFile + ".idx");

                       localFileProvider = new FileSyncProvider(GetReplicaID(cfgFilePath, out serverReplicaId), cfgFilePath, new FileSyncScopeFilter(null, null, System.IO.FileAttributes.Directory, includeList), FileSyncOptions.None);

                        localFileProvider.Configuration.ConflictResolutionPolicy = ConflictResolutionPolicy.ApplicationDefined;

                        RegisterFileCallbacks(localFileProvider);

                    }

     

                    if (serverFileProxy == null)

                    {

                        if (serverReplicaId == Guid.Empty)

                            GetReplicaID(cfgFilePath, out serverReplicaId);

                        serverFileProxy = new FileSyncProviderProxy(serverReplicaId, relativeDirOnServer);

                        RegisterCallbacks(serverFileProxy);

                    }

     

                    SyncOrchestrator agent = new SyncOrchestrator();

                    agent.Direction = GetSyncDirectionOrder(direction);

     

                    agent.LocalProvider = localFileProvider;

                    agent.RemoteProvider = serverFileProxy;

                    SyncOperationStatistics stats = agent.Synchronize();

                }

                catch (Exception e)

                {

                    error = (string)e.Message;

                    return -1;

                }

                return 1;

     

            }


     

    Thursday, July 8, 2010 4:52 PM
  • I seem to have a real problem with the scenario of  

    1. syncing down to the client  (sometimes this will create the files)

    2. making a change on the client

    3. syncing up to the server

    I am only syncing two files in one directory.  On the client, if I re-use the FSP I get the InvalidCastException.  If I don't reuse the FSP on the client, I still have a problem during step 3.  It skips the update on the server because of the NotImplementedException I throw for AbsoluteSourceFilePath even though I have a valid FileStream that should be used.  The stack trace for the exception does not give any useful information. If I don't do the first download sync, I have no problem doing #2 and #3 repeatedly even though I am still throwing the NotImplementedException for AbsoluteSourceFilePath.   Is there something I need to do differently if I want to synchronize in one direction and then later synchronize in the other direction?

    Friday, July 9, 2010 1:13 AM