title: passing Lists from IronPython to C#
body: <p>I want to pass a list of strings from IronPython 2.6 for .NET 2.0 to a C# program (I'm using .NET 2.0 because I'm working with an api that runs off of DLLs built on 2.0). But I'm not sure how to cast it as it comes back from the ScriptEngine.</p>
  
  <pre><code>namespace test1
  {
      class Program
      {
          static void Main(string[] args)
          {
              ScriptEngine engine = Python.CreateEngine();
              ScriptSource source = engine.CreateScriptSourceFromFile("C:\\File\\Path\\To\\my\\script.py");
              ScriptScope scope = engine.CreateScope();
  
              ObjectOperations op = engine.Operations;
  
              source.Execute(scope); // class object created
              object classObject = scope.GetVariable("MyClass"); // get the class object
              object instance = op.Invoke(classObject); // create the instance
              object method = op.GetMember(instance, "myMethod"); // get a method
              List&lt;string&gt; result = (List&lt;string&gt;)op.Invoke(method); // call the method and get result
              Console.WriteLine(result.ToString());
              Console.Read();
          }
      }
  }
  </code></pre>
  
  <p>my python code has a class with a method that returns a python list of strings:</p>
  
  <pre><code>class MyClass(object):
      def myMethod(self):
          return ['a','list','of','strings']
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>Unable to cast object of type 'IronPython.Runtime.List' to type 'System.Collections.Generic.List`1[System.String]'.
  </code></pre>