0

I get the following exception when I try to use a ruby script to modify a list of c# strings.

Unhandled Exception: System.ArgumentException: The value "Scott" is not of type "System.String" and cannot be used in this generic collection.

c#

IList<string> names = new List<string>();
names.Add("scott");
names.Add("jason");

ScriptRuntime runtime = IronRuby.Ruby.CreateRuntime();
ScriptEngine engine = runtime.GetEngine("IronRuby");
ScriptScope scope = engine.CreateScope();
scope.SetVariable("names", names);
engine.ExecuteFile("test.rb", scope);

foreach (var name in names)
{
   Console.WriteLine(name);
}

ruby

names.map! { |item| item.capitalize}
ScArcher2
  • 85,501
  • 44
  • 121
  • 160

1 Answers1

3

Add to_clr_string to the ruby code:

names.map! { |item| item.capitalize.to_clr_string }
Shay Friedman
  • 4,808
  • 5
  • 35
  • 51
  • ha I just came across your blog post when you answered my question here. - http://ironshay.com/post/ironruby-tip-ruby-string-and-clrstring.aspx – ScArcher2 Mar 17 '11 at 15:32