locked
An unhandled exception of type 'System.Runtime.InteropServices.InvalidComObjectException' occurred in Microsoft.Synchronization. RRS feed

  • Question

  • I am builiding my own custom provider using the built in SQL CE metatdata store.

    I am using a windows application to use this sync provider

    Synch happens properly ,but when i close the windows form ,I get this error

     

     

    An unhandled exception of type 'System.Runtime.InteropServices.InvalidComObjectException' occurred in Microsoft.Synchronization.MetadataStorage.dll

    Additional information: COM object that has been separated from its underlying RCW cannot be used.

     

    Any thoughts?

    • Moved by Max Wang_1983 Thursday, April 21, 2011 10:12 PM forum consolidation (From:SyncFx - Technical Discussion [ReadOnly])
    Monday, March 17, 2008 11:15 AM

Answers

  •  

    Thanks for posting a reply Jeremie.

     

    I figured out the solution myself a week back,

    I had to implement the dispose pattern and call dispose on each of the provider explicitly from the form close event.

     

    I made sure that my provider implements the IDisposable interface.

    Here is the code sample for provider.

     

    public class MySyncProvider : KnowledgeSyncProvider, IChangeDataRetriever, INotifyingChangeApplierTarget,IDisposable

        {

     

    ///Constructor and other code.

     

     

    private bool disposed = false;

            public void Dispose()

            {

               

                CleanUp(true);

                GC.SuppressFinalize(this);

            }

     

            private void CleanUp(bool disposing)

            {

               

    if (!this.disposed)

                {

    if (disposing)

                    {

    _metadataStore.Dispose();                   

                    }

                 }

                disposed = true;

            }

     

            ~MySyncProvider()

            {

                CleanUp(false);

            }

    }

     

    Then in the form close event ,I wrote following.

    private void SyncForm_FormClosed(object sender, FormClosedEventArgs e)

            {

                providerA.Dispose();

                providerB.Dispose();

                providerC.Dispose();

            }

     

    My guess is that this is the best way to handle it.

    But I appreciate your reply.

    Friday, March 28, 2008 6:02 AM

All replies

  • Hi Rituraj,

     

    Could you please share the whole repro? Or, if sharing the whole repro is not possible, the try-catch block where this exception is caught?

    Is there any chance the metadata store could be disposed in one thread while still being used in another thread?

     

    Thank you,

    Jeremie

    Wednesday, March 26, 2008 11:19 PM
  •  

    Thanks for posting a reply Jeremie.

     

    I figured out the solution myself a week back,

    I had to implement the dispose pattern and call dispose on each of the provider explicitly from the form close event.

     

    I made sure that my provider implements the IDisposable interface.

    Here is the code sample for provider.

     

    public class MySyncProvider : KnowledgeSyncProvider, IChangeDataRetriever, INotifyingChangeApplierTarget,IDisposable

        {

     

    ///Constructor and other code.

     

     

    private bool disposed = false;

            public void Dispose()

            {

               

                CleanUp(true);

                GC.SuppressFinalize(this);

            }

     

            private void CleanUp(bool disposing)

            {

               

    if (!this.disposed)

                {

    if (disposing)

                    {

    _metadataStore.Dispose();                   

                    }

                 }

                disposed = true;

            }

     

            ~MySyncProvider()

            {

                CleanUp(false);

            }

    }

     

    Then in the form close event ,I wrote following.

    private void SyncForm_FormClosed(object sender, FormClosedEventArgs e)

            {

                providerA.Dispose();

                providerB.Dispose();

                providerC.Dispose();

            }

     

    My guess is that this is the best way to handle it.

    But I appreciate your reply.

    Friday, March 28, 2008 6:02 AM
  • Hi Rituraj -

     

    I am glad that your solution worked for you but we are interested in seeing what the original problem was ? Would it be possible for you to share out your application?  Else, could you capture one of the original stack traces on the exception and send it to us? Also, asking the question Jeremie asked above again in your original implementation is there a possibility that the metadata store was being disposed on one thread while being accessed on another thread?

     

    Thanks
    Deepa

    Saturday, March 29, 2008 12:15 AM
    Answerer