2
votes

I have a .NET application that registers itself as a local COM server (via a LocalServer32 registry entry).

I'm also writing a test client for this application in .NET, but I've noticed something very strange. My COM server is actually being loaded in process instead, which is not what I want.

The test client has no reference to the implementation of the server, so Windows must be looking at my registry, looking at the executable path in LocalServer32, deciding that it is a .NET assembly and loading it as such inside my application?!?

I can force my application to run out of process like this:

Type type = Type.GetTypeFromCLSID(myGuid, "localhost");
var foo = Activator.CreateInstance(type);

However, to me this all seems very unlogical. The COM component is only registered as a server; there is no InProcServer32 registry key under the CLSID.

Is there any way to prevent Windows from being "smart", so no special treatment is required on the client side?

1

1 Answers

0
votes

To have it run as a COM server you would need to set the ApplicationActivation attribute on your assembly.

  1. Add a reference to System.EnterpriseServices.
  2. In your AssemblyInfo.cs file, add the appropriate using statement:

    using System.EnterpriseServices; 
    
  3. Add the assembly attribute:

    [assembly: ApplicationActivation(ActivationOption.Server)]