Erez Cohen
Erez Cohen

Reputation: 1517

Activation Context lost when working with WinForm?

I have an application that uses some classes from a native COM dll in Isolated Deployment.

Simplified:

  1. In run-time I download the dll with its manifest file to a certain directory without registering it.

  2. I then create an Activation Context pointing to that directory and afterwards create instances of classes from the dll.

  3. Let’s say creating class A and after a while class B.

In this flow all goes well.

The problem started when I changed my application to be a WinForm. When "button 1" is pressed I create the Activation Context as before and then create an instance of class A. This works well and the flow returns to my WinForm. However when "button 2" is pressed, I fail to create class B. I get an exception saying that the class cannot be found!

So it seems like the WinForm is somehow messing my Activation context.

Few notes:

Upvotes: 5

Views: 378

Answers (1)

Martyn Lovell
Martyn Lovell

Reputation: 2266

The CLR does not guarantee to maintain/preserve the Win32 Activation Context when passing through managed code.

A workaround is to call native code, set the activation context there, do what you need to, and then restore the context. You probably only need it for loading and binding to the object, so once you have an IUnknown you can return that.

Martyn

Upvotes: 1

Related Questions