Activator.CreateInstance for COM object - locks thread when inside Windows Service???

G

google

The problematic code runs perfectly fine and unmodified when the
application is executed as a standalone .exe. However when the same
code is executed inside Windows Service - it locks up and waits
indefinetely attempting to instantiate COM object with
Activator.CreateInstance.

The service impersonates local admin creadentials.

I am not getting any exceptions, neither raised, nor reported in
systems logs.

Code:

------------------------------------------------------------
Dim oCOMype As Type = Type.GetTypeFromProgID(sProgId)
Log.LogMessage(String.Format("Retrieved type: {0}", sProgId))

Dim oCOMObject As Object = Activator.CreateInstance(oCOMType) '''
<---- will sit on this line indefinetely
Log.LogMessage(String.Format("Instantiated type: {0}",
oCOMType.ToString))
----------------------------------------------------------


Worst part - there are no exception or hints of any kind. What could
this be attributed to? How do i get closer to a solution? I've tried
to set the enclosing thread to STA threading, doesn't help.
 
G

google

Bumping hoping for some COM guru to shine some light upon this issue?
The only solution i've found - is to pull the offending code out.

Thanks.
 
S

sweaty1

One possible reason could be that the COM object is configured to run in the apartment of the first thread that initializes COM (main-thread)

Even when creating a new thread with STA, then the COM object will attempt to load into the main-thread-apartment.

http://stackoverflow.com/questions/...-on-the-thread-that-coinitialize-d-and-create

Possible solutions:
- The COM object doesn't sound like one that should we loaded by a Windows Service, maybe use a system-tray-application instead ?
- Change the ThreadingModel of the COM-class to "Appartment".
- Create a new thread to handle the Windows Service interface, and then use the main-thread for the COM-object. This solution might not work well when the next COM-object arrives, that also requires to be in main-thread.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top