title: C# DLL using PGPCore hanging when called from C++ DLL
body: <blockquote>
  <p>I have written a C# DLL, that encapsulates PGP encryption (using
  PGPCore/BouncyCastle) and SFTP (using SSH.NET), as well as normal FTP
  and a few other functions.  I have used UnmanagedExports to allow it
  to be used from an unmanaged DLL, in this case C++. I am having a
  problem with the functions that rely on the PGPCore and SSH.net
  dependants. The function is called correctly, parameters are correct,
  but instantly hangs the process. Other functions in this DLL called
  from C++, that are not using PGPCore or SSH.Net are working perfectly.
  I load the library in the C++ DLL using LoadLibrary and I have tried
  LoadLibraryEx and giving it the search directory for the dependants.</p>
  <p>I have used DebugDiag to try and pinpoint the problem, but all I get
  from it is :</p>
  <p>Exception 0XE06D7363 on thread 22128. DetailID = 1   Exception
  0XE06D7363 on thread 22128. DetailID = 1   Exception 0XE06D7363 on
  thread 22128. DetailID = 1   System.IO.FileNotFoundException on thread
  22128. DetailID = 25</p>
  <p>Here is a sample function in my c# DLL:</p>
  <p>using Org.BouncyCastle.Bcpg; using Org.BouncyCastle.Bcpg.OpenPgp;
  using Org.BouncyCastle.Security; using PgpCore; using Renci.SshNet;
  using RGiesecke.DllExport;</p>
  <pre><code>   [DllExport(&quot;PGPEncryptFile&quot;, CallingConvention = 
                  System.Runtime.InteropServices.CallingConvention.StdCall)]
      static async void PGPEncryptFile(string KeyFile, string FileToEncrypt, string 
                                EncryptedFile)
      {
  
          try
          {
              // Load keys
              FileInfo publicKey = new FileInfo(KeyFile);
              EncryptionKeys encryptionKeys = new EncryptionKeys(publicKey);
  
              // Reference input/output files
              FileInfo inputFile = new FileInfo(FileToEncrypt);
              FileInfo encryptedFile = new FileInfo(EncryptedFile);
  
              // Encrypt
              PGP pgpEncrypt = new PGP(encryptionKeys);
              await pgpEncrypt.EncryptFileAsync(inputFile, encryptedFile);
          }
          catch (Exception)
          {
              throw;
          }
  </code></pre>
  </blockquote>
  <p>Can anyone point me in the right direction? Should I be able to call wrapped PGPCore functions from a C++ DLL?</p>