Unable to cast COM object of type exception

前端 未结 4 1824
感情败类
感情败类 2020-12-09 09:34

I have the following code:

public void Test(IMyInterface iInterface)
{
  iInterface.CallMethod ( );
}

Which works fine. However, if I chang

4条回答
  •  眼角桃花
    2020-12-09 10:30

    I've been developing a C# application which uses 7-zip through COM interfaces. I ran into this funny thing where I was able to extract archives from a worker thread in one instance, but not another, getting this same exception.

    I found that, so long as you initialize the offending COM object in the thread where it is used no exception is thrown. My solution was to dispose the objects which utilized COM interfaces and re-initialize them when passing them between threads.

提交回复
热议问题