title: Unable to access a different recipients account folders with C# Interop.Outlook
body: <p>I'm trying to access my spam folder on a different account in my Outlook.
  In my Outlook account I have 3 email accounts set, where 2 are work related and 1 is personal. </p>
  
  <p>I managed to acces the emails in my main account by using the following code:</p>
  
  <pre><code>ns = Application.GetNamespace("MAPI");
  inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
  items = inbox.Items;
  </code></pre>
  
  <p>This works perfectly. <br >
  However, when I try to access a different account, I get the following error:</p>
  
  <blockquote>
    <p>System.Runtime.InteropServices.COMException: 'The operation failed because of a registry or installation problem. Restart Outlook and try again. If the problem persists, reinstall.'</p>
    
    <p>at Microsoft.Office.Interop.Outlook.NameSpaceClass.GetSharedDefaultFolder(Recipient Recipient, OlDefaultFolders FolderType) <br>
       at DemoAntiSpam2.ThisAddIn.ThisAddIn_Startup(Object sender, EventArgs e) in C:\Projects\T\DemoAntiSpam2\DemoAntiSpam2\ThisAddIn.cs:line 29 <br>
       at Microsoft.Office.Tools.AddInImpl.OnStartup() <br>
       at DemoAntiSpam2.ThisAddIn.FinishInitialization() in C:\Projects\T\DemoAntiSpam2\DemoAntiSpam2\ThisAddIn.Designer.cs:line 57 <br>
       at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.ExecuteCustomization.ExecutePhase(ExecutionPhases executionPhases)
       at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.ExecuteCustomization.Microsoft.VisualStudio.Tools.Office.Runtime.Interop.IExecuteCustomization2.ExecuteEntryPoints()</p>
  </blockquote>
  
  <pre><code>Outlook.NameSpace ns;
  Outlook.MAPIFolder inbox;
  Outlook.Items items;
  
  private void ThisAddIn_Startup(object sender, System.EventArgs e)
  {
      ns = Application.GetNamespace("MAPI");
      var recipient = ns.CreateRecipient(recipientAddress);
      recipient.Resolve();
      if (recipient.Resolved)
      {
          // Code breaks here.
          inbox = ns.GetSharedDefaultFolder(recipient, Outlook.OlDefaultFolders.olFolderInbox);
          items = inbox.Items;
          items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(items_ItemAdd);
      }
  }
  </code></pre>