title: WinSCP C# first use
body: <p>I installed WinSCP on my PC and want to get a connection to another server through a C# Console Application. </p>
  
  <pre><code> using WinSCP;
  namespace WINSCP_SFTP
  {
      class Program
      {
          static void Main(string[] args)
          {
              try
              {
                  Console.WriteLine("test");
                  SessionOptions sessionOptions = new SessionOptions
                  {
                     Protocol = Protocol.Sftp,
                     HostName = "hostname",
                     UserName = "user",
                     Password = "password"
                   };
  
                   using (Session session = new Session())
                   {
                      session.ExecutablePath = @"C:\Program Files\WinSCP";
                      session.Open(sessionOptions);
  
                      Console.WriteLine(session.Opened);
                   }
              }
              catch (Exception ex)
              {
                  Console.WriteLine(ex.Message);
              }
  
              Console.ReadLine();
          }
      }
  }
  </code></pre>
  
  <p>But if I run the .exe, the application crashs even before the first console.writeline appears.. Any ideas what I'm doing wrong?</p>
  
  <p>Update:
  An alert pops up which says: WINSCP_SFTP has stopped working.. then in the cmd line a text appears: Unhandled Exception.. I tried to make a try..catch around my whole code but it also doesn't catch the error</p>
  
  <p>Error that occurs(Picture from web, not a screenshot of my application):
  <img src="https://i.stack.imgur.com/AUUsf.png" alt="enter image description here"></p>