Question

I'm pretty sure the answer is no but just in case:

For a stand alone exe with an appropriate SxS manifest, is it possible to reference COM DLL's using a relative path or load them from a directory that is not the current directory?

We're operating in a grid environemnt that deploys various packages (i.e. zip files) using a common folder as the root. Several apps would like to reference a common COM Api (with DLL manifests) from a common location. However, as the grid environment is sandboxed we can't install to the Windows SxS directory and we also can't do it out of band (i.e. not deployed by the grid).

Do I have any hope of saying load COM.DLL from ..\SomeCommonDir\COM.dll or C:\Program Files\SomeCommonDir\COM.DLL ?

Everything works fine as a private assembly.

Was it helpful?

Solution

This should be possible using Activation Contexts. (I'm assuming that you OK with manifest etc as it sounds like you're able to get it working fine the 'standard' way...)

There's the 'hardcore' way of doing things here, or you can use the Microsoft.Windows.ActCtx object. These both allow you to manually / programmatically set the location of the client manifest for the Activation Context; the client manifest does have to be in the same folder as the assembly manifest and the assembly.

This SO question may be of use to you. And here's a snippet of one way to do it...

// Create an activation context
Type actCtxType = System.Type.GetTypeFromProgID("Microsoft.Windows.ActCtx");
dynamic actCtx = System.Activator.CreateInstance(actCtxType);
actCtx.Manifest = @"Path\To\COMClient.manifest";

// Create the object you want, using the activation context
dynamic obj = actCtx.CreateObject("COMTestService.COMTestObject");

// Now use it!
var question = obj.GetQuestionFromAnswer(42);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top