I have a CLR dll which declares an enumeration FieldID. It's just an
ordinary C# enum
I have the following code which used to work under 0.9

fields_to_read = [FieldID.DBID, FieldID.Name]
clr_fields = System::Array[FieldID].new fields_to_read

Under 0.9.1, the following exception occurs:

System::InvalidCastException: The result type 'System.Int32' of the dynamic
binding produced by binder 'ConvertToFixnumAction @1' is not compatible with
the result type 'Interop.FieldID' expected by the call site.
        from Microsoft.Scripting.Core:0:in `Bind'
        from Microsoft.Scripting.Core:0:in `BindCore'
        from (irb):71
        from :0:in `eval'
        from workspace.rb:80:in `evaluate'
        from context.rb:217:in `evaluate'
        from irb.rb:147:in `eval_input'
        from irb.rb:257:in `signal_status'
        from irb.rb:146:in `eval_input'
        from ruby-lex.rb:230:in `each_top_level_statement'
        from :0:in `loop'
        from C:/Dev/TEST/ruby/lib/ruby/1.8/irb.rb:146:in `eval_input'
        from C:/Dev/TEST/ruby/lib/ruby/1.8/irb.rb:70:in `start'
        from :0:in `catch'
        from C:/Dev/TEST/ruby/lib/ruby/1.8/irb.rb:69:in `start'
        from C:/Dev/TEST/ruby/bin/iirb:13

Has the behavior for converting ruby arrays to CLR arrays changed? I'm
working around it for now by doing this:

tmp = System::Collections::Generic::List.of(FieldID).new
fields_to_read.each{|f| tmp.add f}
clr_fields = tmp.to_array

Note: I wanted to just pass the fields_to_read ruby array into the
constructor of List<T>, but when I do this, IronRuby is selecting the
constructor overload which takes an int32 for capacity, rather than the
overload which takes IEnumerable<T>, and I get the following error:

tmp = System::Collections::Generic::List.of(FieldID).new(fields_to_read)
TypeError: can't convert Array into Fixnum
        from (irb):75
        from C:/Dev/TEST/ruby/lib/ruby/1.8/irb.rb:146:in `eval_input'
        from :0:in `eval'
        from workspace.rb:80:in `evaluate'
        from context.rb:217:in `evaluate'
        from irb.rb:147:in `eval_input'
        from irb.rb:257:in `signal_status'
        from irb.rb:146:in `eval_input'
        from ruby-lex.rb:230:in `each_top_level_statement'
        from :0:in `loop'
        from C:/Dev/TEST/ruby/lib/ruby/1.8/irb.rb:70:in `start'
        from C:/Dev/TEST/ruby/lib/ruby/1.8/irb.rb:69:in `start'
        from :0:in `catch'
        from C:/Dev/TEST/ruby/bin/iirb:13

Is this also a bug?

Thanks a lot, Orion
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core

Reply via email to