title: Unit Test fail with HRESULT: 0x80070005 (E_ACCESSDENIED) on TFS
body: <p>I have an Outlook Add in where I am using <em>Microsoft.Office.Interop.Outlook.Storageitem</em> to save my settings.</p>
  
  <p>Most of my tests access the settings to set or get the configuration for contacting the server.</p>
  
  <p>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:</p>
  
  <blockquote>
    <p>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)).</p>
  </blockquote>
  
  <p>The error occurs when the test is calling the following codeline.</p>
  
  <pre><code>Folder inbox = (Folder) new Microsoft.Office.Interop.Outlook.Application().GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderInbox);
  </code></pre>
  
  <p>I asume that the error appears because the test tries to access an <em>Application</em> of <em>Outlook</em> and does not have the permission.</p>
  
  <ul>
  <li>Outlook is instaled on the <strong>Windows Server 2012</strong> where TFS is running.</li>
  <li>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.)</li>
  <li>The <em>C:\Windows\SysWOW64\config\systemprofile\Desktop</em> folder exists.</li>
  <li>I already have set all permissions for the user <strong>NETWORK SERVICE</strong> in <em>Controlpanel->Administrative tools->Component Services->computers-> myComputer->DCOM Config->Microsoft Outlook</em>
  <a href="https://i.stack.imgur.com/ZkoGe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZkoGe.png" alt="enter image description here"></a></li>
  </ul>
  
  <p>I also found <a href="https://stackoverflow.com/questions/18152049/excel-automation-failing-on-server-access-denied-hresult-0x80070005-e-access">this question</a> which has no answer to my problem.</p>
  
  <p>Are there any other steps i could try to give my tests access to run the tests sucessfully?</p>