Unable to cast COM object of type 'System.__ComObject' to interface type 'ISyncKnowledge2'. RRS feed

  • Question

  • I'm back again (much to everyone's dismay).  I spent a lot of time developing a sync prototype that, if successful, could be pulled into our application.  It was successful and I am in the process of pulling MSF 2.0 into our application.  I just did my first sync and it seems to have worked (kind of hard to say since it didn't really have any data to sync) and I got the following error:

    Exception: Unable to cast COM object of type 'System.__ComObject' to interface type 'ISyncKnowledge2'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{ED0ADDC0-3B4B-46A1-9A45-45661D2114C8}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

    The error was output to the console on my client side; there were no complaints on the server side.

    As far as the sync is concerned, this was a single table sync where the sync change tracking framework was added to an existing table.  Therefore, when I initiated the sync, the tracking table for table has no data in it in both the client database and the server database.  So the net effect is that no data is actually synced.

    My questions are actually fairly easy.  First, is this error something I should be concerned about?  Second, if I should be concerned about this error, what do I need to do to fix it?



    Wednesday, June 2, 2010 2:50 PM

All replies

  • Hey,


    Could you please post the call stack for the exception to help identify the possible issues? and are you writing your own custom provider?



    Ann Tang
    Wednesday, June 2, 2010 6:40 PM
  • Ann,

    I am going to try to get you a call stack.  I saw this occur one time and then it didn't occur for a while (probably because I was fixing bugs in my code).  Once I started syncing again, I could get this to occur pretty easily; at least until I saw your request for stack trace.  Then it hasn't happened again :).  But I will get one and post it as soon as I can.

    In answer to your question, I am in fact providing my own "semi-custom" providers.  My sync providers are based on "Web sync" demo application (sync two SQL Server databases over WCF), but I built them dynamically using custom table adapters that I also generate dynamically.  I "reverse engineered" these by looking at the code generated by the sync provisioning classes.  There is a reason for this and it worked very well in my original prototype, but it could have a bug or two floating around in it.

    As soon as I can get a call stack, I will post it here.

    Thanks for the prompt response.


    Wednesday, June 2, 2010 7:04 PM
  • Ann,

    Here is a stack trace for this error:

    Server stack trace:

    at System.ServiceModel.Channels.InputQueue`1.WaitQueueReader.Wait(TimeSpan timeout, T& value)

    at System.ServiceModel.Channels.InputQueue`1.Dequeue(TimeSpan timeout, T& value)

    at System.ServiceModel.Channels.InputQueueChannel`1.Dequeue(TimeSpan timeout, TDisposable& item)

    at System.ServiceModel.Channels.DuplexChannel.TryReceive(TimeSpan timeout, Message& message)

    at System.ServiceModel.Dispatcher.DuplexChannelBinder.Request(Message message, TimeSpan timeout)

    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)

    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)

    at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)

    at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    Exception rethrown at [0]:

    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

    at ABB.SyncContracts.WebSync.ISync.GetChanges(UInt32 batchSize, SyncKnowledge destinationKnowledge)

    at ABB.SyncCommon.SyncProviderProxy.GetChangeBatch(UInt32 batchSize, SyncKnowledge destinationKnowledge, Object& changeDataRetriever) in C:\Projects\Applications\ServicePRO\branches\NewSync\Source\ABB.SyncCommon\SyncProviderProxy.vb:line 113

    at Microsoft.Synchronization.KnowledgeProviderProxy.GetChangeBatch(UInt32 dwBatchSize, ISyncKnowledge pSyncKnowledge, ISyncChangeBatch& ppChangeBatch, Object& ppUnkDataRetriever)

    at Microsoft.Synchronization.CoreInterop.ISyncSession.Start(CONFLICT_RESOLUTION_POLICY resolutionPolicy, _SYNC_SESSION_STATISTICS& pSyncSessionStatistics)

    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 ABB.SyncCommon.SyncHelper.ExecuteSync(String clientDbName, DbSyncProvider clientProvider, KnowledgeSyncProvider serverProvider, SyncDirectionOrder direction) in C:\Projects\Applications\ServicePRO\branches\NewSync\Source\ABB.SyncCommon\SyncHelper.vb:line 77

    Anything with "ABB" in the class name is my code.  Does this help?  Is there any other information that I can provide?  Is there something else I can look at?

    Thanks, I really appreciate the assistance.


    Wednesday, June 2, 2010 7:13 PM
  • Please check out section "Managed Application Throws System.Runtime.InteropServices.COMException (0x80004002)" of SyncFX troubleshoot @http://msdn.microsoft.com/en-us/library/cc807380.aspx   and see if it might be helpful.


    Ann Tang
    Wednesday, June 2, 2010 9:38 PM
  • I followed the link you provided and that article did contain a section that was relevant to my problem.  To summarize, the Sync Framework does not implement the IMarshal interface and apparently this causes problems when the client side and service side are being run in different threads in the same application.  To circumvent this, one must run the client and service as Managed Thread Apartment (MTA) threads.

    I have no idea what that means but it was enough of a clue to get around this issue.

    I was actually running my service as a "console application" from inside Visual Studio 2005 for ease of debugging and was running the client application from inside the same instance of Visual Studio.  My guess is that Visual Studio is running these applications as separate non-MTA threads and this is causing the problem.  To test that, I simply ran the service as a standalone console application outside of Visual Studio and I have not seen this particular error again.  It looks like I may have other issues to deal with (because never seems to come easy with this), but for now I appear to be past this one.


    Thursday, June 3, 2010 3:21 PM
  • Working with MS Sync2.1 and Sql Server Express to Sql Server over WCF Services I was getting this error when I had manually modified the database tables and the tracking tables were then out of sync with the real tables. I deleted all tables MS Sync generated, and they were regenerated on next Sync, which was successful.

    This only happens in unit tests, and semi-randomly. Retry test. Seems to work better with local Sql Express install, as opposed to using database on server.
    Likely threading issue as for one of my tests if set my custom VerboseLogging = true AND SyncTracer = 4 (verbose) AND debug unit test will hit this.
    I've never seen in production, and based on other peoples posts seems to do with Client and Server running on seperate threads in the same application. So if client and server on seperate machines as in production then not an issue.
    Reason: This exception occurs when a Sync Framework object is created in one single-threaded apartment and a method of the object is called from a different single-threaded apartment. In this case, the .NET Framework tries to marshal the Sync Framework object from one apartment to the other by querying the Sync Framework object for the IMarshal interface. Sync Framework objects do not implement IMarshal and so the call fails with this exception.
    Solution: Use multithreaded apartment (MTA) threads. Marshaling is not required for MTA threads.

    • Edited by HoldFast Stark Friday, April 25, 2014 2:33 PM Added more detail
    Tuesday, December 10, 2013 5:20 PM