title: C# not connecting to R using RDotNet
body: <p>I am trying to interface C# to R using <code>RDotNet</code>. </p>
  
  <p>The following code is wants R to calculate the sum of two numbers and C# to get the result back and display it in the command window. </p>
  
  <pre><code>using System;
  using RDotNet;
  
  namespace rcon
  {
  class Program
  {
      static void Main(string[] args)
      {
          string dllPath = @"C:\Program Files\R\R-3.1.0\bin\i386";
  
          REngine.SetDllDirectory(dllPath);
          REngine.CreateInstance("RDotNet");
  
          //REngine engine = REngine.GetInstanceFromID("RDotNet");
  
          using (REngine engine = REngine.GetInstanceFromID("RDotNet"))
          {
              var x = engine.Evaluate("x &lt;- 1 + 2");
              Console.WriteLine(x);
          }
      }
  }
  }
  </code></pre>
  
  <p>but when I try to send the command to R and get back the calue in x I got an error: </p>
  
  <blockquote>
    <p>"InvalidOperationException was unhandled" </p>
    
    <p>"Operation is not valid due to the current state of the object."</p>
  </blockquote>
  
  <p>If I explore the object "engine" I see that <code>IsRunning=false</code>. </p>
  
  <p>Can this be the problem? And how can I fix this in order to be able to interface to R? </p>