I have a statefull legacy COM object. And I need to properly set state and call operation on it.
It works fine until I try do this logic sequentially on the same object (got error because of how this component written). So I need fresh COM object for each iteration.
I get COM object like this:
Activator.CreateInstance(Type.GetTypeFromProgID("MyComType"));
And release objects like this:
public void close()
{
createdComObjects.Reverse();
foreach(object item in createdComObjects)
{
Marshal.FinalReleaseComObject(item); //also tried ReleaseComObject
}
}
But this does not work... I get the same COM instance every time and legacy error because of not fresh state.
And one more detail – when I run .exe with one business logic iteration, everything works fine and I can even parallel .exe calls in different consoles without state error.
So questions are:
- How can I use
Activator.CreateInstance
to get a fresh instance on every call? (just like separate .exe invocations do) - How can I fully release instances in order to get fresh ones on next call? (just like exit from .exe does)