E_ACCESSDENIED when trying to launch a COM application from NUnit launched by TeamCity


I'm having issues with a certain NUnit test that tries to launch a COM application in its Testfixture Setup. I get the following error:

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'AUTOMATIONOBJECTSLib.IApplication'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}' failed due to the following error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

I get this error only when launching from Team City both if I use TeamCities build runner step or if I launch NUnit from a Command Line step.

If I run the same command line step from a command console manually on the Build agent, it works fine.

I have the TeamCity Build agent running under the logged in context of an administrator user, and I can see that the Nunit-console exe is running under that user in task manager.

Any help or hints appreciated.



1 comment
Comment actions Permalink

Hi Chad,

Do you run agent as service? If yes, then please try to start in from command line. Please see the related documentation.
Do you have antivirus installed? If yes, then please try to unistall it.
If nothing helps, then please follow all the steps from this guideline and provide us with logs.


Please sign in to leave a comment.