title: Exceptions raised running COM DLL
body: <p>I will try again .... :)</p>
  
  <p>If I have this code:</p>
  
  <pre><code>void CTestDlg::OnBnClickedButtonTest()
  {
      MSAToolsLibrary::IMSAToolsLibraryInterfacePtr p;
      HRESULT hr;
      hr = p.CreateInstance(__uuidof(MSAToolsLibrary::MSAToolsLibraryClass));
      if (FAILED(hr))
      {
          __int64 i;
          p-&gt;SetPathXML(m_strPublisherDatabaseXML.AllocSysString(), &amp;i);
          p-&gt;ReadPublisherData(&amp;i);
      }
  }
  </code></pre>
  
  <p>And I run it, I get this silent exception:</p>
  
  <pre><code>Exception thrown at 0x00007FFCD00B7788 (KernelBase.dll) in Test.exe: 0x04242420 (parameters: 0x0000000031415927, 0x00007FFCBF6C0000, 0x00000099D88FBDC0).
  </code></pre>
  
  <p>But, if I use a wrapper (header:</p>
  
  <pre><code>#pragma once
  
  #import "D:\\My Programs\\2017\\MSAToolsLibrary\\MSAToolsLibrary\\bin\\Release\\MSAToolsLibrary.tlb" raw_interfaces_only named_guids
  
  class CMSATools
  {
  public:
      CMSATools();
      ~CMSATools();
      void SetPathXML(CString strPath);
      void OpenPublisherDatabase();
  
  private:
      MSAToolsLibrary::IMSAToolsLibraryInterfacePtr m_pInterface;
  }
  </code></pre>
  
  <p>Class:</p>
  
  <pre><code>#include "stdafx.h"
  #include "MSATools.h"
  
  
  CMSATools::CMSATools()
  {
      m_pInterface = NULL;
  
      HRESULT hr;
      hr = m_pInterface.CreateInstance(__uuidof(MSAToolsLibrary::MSAToolsLibraryClass));
      if (FAILED(hr))
      {
          // TODO: Throw exception ?
      }
  }
  
  
  CMSATools::~CMSATools()
  {
  }
  
  void CMSATools::SetPathXML(CString strPath)
  {
      if (m_pInterface != NULL)
      {
          CComBSTR    bstrText = strPath.AllocSysString();
          __int64     iResult;
  
          m_pInterface-&gt;SetPathXML(bstrText, &amp;iResult);
      }
  }
  
  void CMSATools::OpenPublisherDatabase()
  {
      __int64 iResult;
  
      if (m_pInterface != NULL)
          m_pInterface-&gt;ReadPublisherData(&amp;iResult);
  }
  </code></pre>
  
  <p>And use this in MFC instead:</p>
  
  <pre><code>void CTestDlg::OnBnClickedButtonGetNames()
  {
      CMSATools toolsMSA;
  
      UpdateData(TRUE);
  
      toolsMSA.SetPathXML(m_strPublisherDatabaseXML);
      toolsMSA.OpenPublisherDatabase();
  }
  </code></pre>
  
  <p>It is doing the same thing, yet I get these silent exceptions:</p>
  
  <pre><code>Exception thrown at 0x00007FFCD00B7788 (KernelBase.dll) in Test.exe: 0x04242420 (parameters: 0x0000000031415927, 0x00007FFCBF6C0000, 0x00000090F277C040).
  Exception thrown at 0x00007FFCD00B7788 in Test.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x00000090F277BB80.
  Exception thrown at 0x00007FFCD00B7788 in Test.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
  Exception thrown at 0x00007FFCD00B7788 in Test.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x00000090F277BB80.
  Exception thrown at 0x00007FFCD00B7788 in Test.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
  Exception thrown at 0x00007FFCD00B7788 in Test.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x00000090F277BB80.
  Exception thrown at 0x00007FFCD00B7788 (KernelBase.dll) in Test.exe: 0xE0434352 (parameters: 0xFFFFFFFF80070002, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFCBF6C0000).
  </code></pre>
  
  <p>Why should one way work and the other cause exceptions (that I can't seem to even detect)?</p>
  
  <h2>UPDATE</h2>
  
  <p>Please hold off - I see my stupid error now! One moment ....</p>
  
  <h2>UPDATE 2</h2>
  
  <pre><code>void CTestDlg::OnBnClickedButtonTest()
  {
      MSAToolsLibrary::IMSAToolsLibraryInterfacePtr p;
      HRESULT hr;
      hr = p.CreateInstance(__uuidof(MSAToolsLibrary::MSAToolsLibraryClass));
      if (SUCCEEDED(hr))
      {
          __int64 i;
          p-&gt;SetPathXML(m_strPublisherDatabaseXML.AllocSysString(), &amp;i);
          p-&gt;ReadPublisherData(&amp;i);
      }
  }
  </code></pre>
  
  <p>I corrected the test case now and they both have the same exceptions raised. This is the method that seems to cause the problem in the DLL:</p>
  
  <pre><code>public void ReadPublisherData(out Int64 iResult)
  {
      iResult = MakeResult(true);
  
      try
      {
          _PublisherData.Publishers.Clear(); // Reset
  
          XmlSerializer x = new XmlSerializer(_PublisherData.GetType());
          using (StreamReader reader = new StreamReader(_strPathXML))
          {
              _PublisherData = (PublisherData)x.Deserialize(reader);
              _PublisherData.BuildPublisherDictionaryFromList();
              iResult = _PublisherData.PublisherDictionary.Count;
          }
      }
      catch
      {
          iResult = MakeResult(false);
      }
   }
  </code></pre>
  
  <p>As far as I am aware it doesn't cause any exceptions. It seems ...</p>