0
votes

I have an Outlook Add in where I am using Microsoft.Office.Interop.Outlook.Storageitem to save my settings.

Most of my tests access the settings to set or get the configuration for contacting the server.

On my local machine all of the tests are running fine. But when I check in my project into TFS and run the tests there all of them fail with the Error:

System.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

The error occurs when the test is calling the following codeline.

Folder inbox = (Folder) new Microsoft.Office.Interop.Outlook.Application().GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderInbox);

I asume that the error appears because the test tries to access an Application of Outlook and does not have the permission.

  • Outlook is instaled on the Windows Server 2012 where TFS is running.
  • Also Outlook was started once with having no Mailaccount configured. (The test runs fine when i start it manually on a machine with a Outlook with no Mailaccount configured.)
  • The C:\Windows\SysWOW64\config\systemprofile\Desktop folder exists.
  • I already have set all permissions for the user NETWORK SERVICE in Controlpanel->Administrative tools->Component Services->computers-> myComputer->DCOM Config->Microsoft Outlook enter image description here

I also found this question which has no answer to my problem.

Are there any other steps i could try to give my tests access to run the tests sucessfully?

3
I have written several Office add-ins using TDD. My advice is that your unit tests project should not use the real Outlook object model. The test project should not even reference the Interop assemblies. The good news is interop assemblies expose only interface which make them really mockable with a Mock framework such as Moq github.com/Moq/moq4 - Benoit Patra
Which version of TFS are you using? Do you use XAML build or vNext build? How did you configure build definition? - Cece Dong - MSFT

3 Answers

1
votes

Outlook is instaled on the Windows Server 2012 where TFS is running.

I already have set all permissions for the user NETWORK SERVICE in Controlpanel->Administrative tools->Component Services->computers-> myComputer->DCOM Config->Microsoft Outlook

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.

1
votes

No Office app (Outlook included) can be used in a service. I don't think actually creating an instance of Outlook.Application is a good idea in a unit test.

0
votes

Try changing the TFS build server to run as a user with admin rights on the box. I would not suggest leaving this configuration.