Vilx-
Vilx-

Reputation: 106980

How to specify which COM server my .NET interop should use?

I've got a .NET application which uses a COM server. The COM server is registered on the machine where I run it, so when my code reaches new MyInterop.SomeObject() the appropriate MyComServer.exe is started.

However, as I'm debugging, I've got several copies of MyComServer.exe residing in different folders with different configuration files. I would like to specify which my app should load.

Two workarounds that I know of are:

Is there anything more appropriate?

Upvotes: 1

Views: 131

Answers (2)

Hans Passant
Hans Passant

Reputation: 942119

The COM server .exe got started by your new MyInterop.SomeObject() call. You've no doubt got so many .exe's running because you terminated the program while debugging, without allowing .NET to shutdown properly and decrease the reference count in the finalizer thread. COM doesn't have a mechanism to clean-up these lost references. Simply use Taskmgr.exe, Process tab to kill the running instances.

COM has a mechanism to attach to a running instance of a server through the ROT (Running Object Table). This is however not something you can bolt on later, it has to be explicitly supported by the server. If you do have to option to tinker with the server then do consider making it an in-process server instead. Much less troublesome.

Upvotes: 1

Alan Stephens
Alan Stephens

Reputation: 579

You could try creating the config file dynamically based on debug version.

Upvotes: 0

Related Questions