locked
COM Exception while working with Provider.DetectChanges RRS feed

  • Question

  •  

    Hi All

     

    I am getting a COM exception while calling the DetectChanges

    Exception details

     

    Unable to cast COM object of type 'Microsoft.Synchronization.Files.Interop.FileSyncProviderClass' to interface type 'Microsoft.Synchronization.Files.Interop.IFileSyncProvider'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{73EA794F-1251-4466-A19C-DAEAF5BDBD04}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

     

    I have created a Sync class which encapsulate all the sync related functions and I am invoking the Sync method using delegates for Async call, then I am getting this error. If I am not using delegates it is working fine.

     

    Please help me.

    Wednesday, April 2, 2008 3:28 PM

Answers

  • Hi Anuraj,

     

    This problem occurs when the CLR attempts to marshal providers between threads.

     

    There are two possible workarounds:

     

    Option 1: Use MTA

     

    To create your main thread MTA, please try applying the MTAThreadAttribute to your Sub Main.To do so, annotate as follows:

     

    <MTAThread> Sub Main()

     

    Note, however, this solution should not be used if you intend to use WinForms from your main thread as WinForms must be called from an STA thread.

     

    Option 2: Instantiate providers on the same thread as sync session

     

    In your case, you would do this by creating the provider instances within your delegate function. This will ensure the providers are created on the same thread as the sync session, thus removing the need for the CLR to marshal.

     

    Please let me know whether or not this resolves your issue.

     

    Thanks,

    Neil

    Monday, May 12, 2008 10:09 PM

All replies

  • Are you using CTP2 of the Sync Framework?

     

    Liam

     

    Monday, April 7, 2008 5:49 PM
  • Beyond my previous question, we having a little difficult determining where the issue you are having is.

     

    Is it possible for you to create both managed threads (the one creating the component and the delegate thread) as MTA threads to see if that resolves the problem?

     

    Liam

    Monday, April 7, 2008 8:18 PM
  • Hi Liam

     

    Sorry for late reply. I am using CTP 2. And the code is like this

     

    I have class name SyncHelper, with a function Sync(). I am passing the local and remote provider paths as the arguments to the constructor. And I have tried to call the function as Async like this. I have created a Delegate in the namespace outside the class SyncHelper class.

     

    Public delegate sub SyncDelegate()

     

    then in the client application(which uses the SyncHelper class)

     

    Dim _SyncHelper as new SyncHelper(LocalPath, RemotePath)

    Dim _SyncDelegate as new SyncDelegate(AddressOf _SyncHelper.Sync)

    Dim _Result as IAsyncResult

    IAsyncResult = _SyncDelegate.BeginInvoke(nothing, nothing)

     

    Then I will get the exception, if I call Invoke instead of BeginInvoke the function works fine. Otherwise I am getting the exception from LocalProvider.DetectChanges().

     

    Sorry I do have much understanding with threads can you help me how can I do that?

     

    Please help

     

    regards

    Anuraj

    Wednesday, April 9, 2008 2:46 PM
  • Hi Anuraj,

     

    This problem occurs when the CLR attempts to marshal providers between threads.

     

    There are two possible workarounds:

     

    Option 1: Use MTA

     

    To create your main thread MTA, please try applying the MTAThreadAttribute to your Sub Main.To do so, annotate as follows:

     

    <MTAThread> Sub Main()

     

    Note, however, this solution should not be used if you intend to use WinForms from your main thread as WinForms must be called from an STA thread.

     

    Option 2: Instantiate providers on the same thread as sync session

     

    In your case, you would do this by creating the provider instances within your delegate function. This will ensure the providers are created on the same thread as the sync session, thus removing the need for the CLR to marshal.

     

    Please let me know whether or not this resolves your issue.

     

    Thanks,

    Neil

    Monday, May 12, 2008 10:09 PM