views:

55

answers:

2

We have some C# code that uses COM (its calling legacy code).

When an event happens, a COM event is fired.

Everything works perfectly.

However, if we call that same code from within a unit test, then suddenly the COM events cease to be fired - its just silence, like some sort of empty room with no party.

Any ideas why?

Environment:

  • Microsoft Visual Studio 2008.
  • Unit testing using the built in unit testing for MSVS 2008
+2  A: 

Without further details, this is hard to diagnose. However, it is possible that this is actually an apartment issue: IIRC, VS runs tests in an STA. If your application uses an MTA to run the same code, it could be that you are facing deadlocking or similar issues.

Johannes Passing
A: 

Well, we couldn't fix it, so we managed to work around it by switching to using a version of the API that uses sockets rather than COM. Everything works perfectly now.

I'm 90% sure that the COM API we are using is based on MTA (Multi Threaded Apartment) rather than a STA (Single Threaded Apartment). From what I know about COM, MTA and STA don't mix in the same space.

I'm voting for your answer, because that's the only explanation I can think of that would explain the complete absence of COM events during a unit test.

Gravitas