# 0.9.1 regression when creating System::Array of clr enum values

**URL:** <https://www.ruby-forum.com/t/0-9-1-regression-when-creating-system-array-of-clr-enum-values/176391>\
**Category:** IronRuby\
**Created:** [September 30, 2009, 12:32am UTC](https://www.ruby-forum.com/t/0-9-1-regression-when-creating-system-array-of-clr-enum-values/176391 "2009-09-30T00:32:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Orion\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/65b543/32.png) [@Orion\_E](https://www.ruby-forum.com/u/Orion_E)\
**Post date:** [September 30, 2009, 12:32am UTC](https://www.ruby-forum.com/t/0-9-1-regression-when-creating-system-array-of-clr-enum-values/176391/1 "2009-09-30T00:32:00Z")

</div>

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, but when I do this, IronRuby is selecting the  
constructor overload which takes an int32 for capacity, rather than the  
overload which takes IEnumerable, 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

---

<div class="post-metadata">

**Author:** ![Orion\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/65b543/32.png) [@Orion\_E](https://www.ruby-forum.com/u/Orion_E)\
**Post date:** [September 30, 2009, 1:27am UTC](https://www.ruby-forum.com/t/0-9-1-regression-when-creating-system-array-of-clr-enum-values/176391/2 "2009-09-30T01:27:39Z")

</div>

The error message seems to indicate this is the same issue you had in  
your “Another 0.9.1 regression” mail.

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Orion E.  
Sent: Tuesday, September 29, 2009 3:32 PM  
To: removed\_email\_address@domain.invalid  
Subject: [Ironruby-core] 0.9.1 regression when creating System::Array of  
clr enum values

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, but when I do this, IronRuby is selecting the  
constructor overload which takes an int32 for capacity, rather than the  
overload which takes IEnumerable, 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

---

<div class="post-metadata">

**Author:** ![Orion\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/65b543/32.png) [@Orion\_E](https://www.ruby-forum.com/u/Orion_E)\
**Post date:** [September 30, 2009, 1:39am UTC](https://www.ruby-forum.com/t/0-9-1-regression-when-creating-system-array-of-clr-enum-values/176391/3 "2009-09-30T01:39:22Z")

</div>

Hrm… I’m trying to get some sample code so I can provide a repro for  
you  
guys, but it’s proving difficult. The following C# code is _all_ fine  
when  
called from IronRuby

public static class II  
{  
public static void GetData(this string str, int inint, out int  
outint,  
out string outstr)  
{  
outint = inint \* 10;  
outstr = outint.ToString();  
Console.WriteLine(“str=”+str);  
}

```
public static void GetXHR(this string str, out 

```

MSXML2.IXMLHTTPRequest  
xhr)  
{  
xhr = new MSXML2.XMLHTTPClass();  
}

```
public static void GetDualXhrFromCoClass(this string str, out

```

MSXML2.IXMLHTTPRequest xhr1, out MSXML2.IXMLHTTPRequest xhr2)  
{  
xhr1 = new MSXML2.XMLHTTPClass();  
xhr2 = new MSXML2.XMLHTTPClass();  
}

```
public static void GetDualXhrFromCLSID(this string str, out object 

```

xhr1,  
out object xhr2)  
{  
var t = Type.GetTypeFromCLSID(new  
Guid(“F6D90F16-9C73-11D3-B32E-00C04F990BB4”)); // guid of  
MSXML2.XMLHTTPClass  
xhr1 = Activator.CreateInstance(t);  
xhr2 = Activator.CreateInstance(t);  
}

```
public static void GetDualXhrWithCast(this string str, out

```

MSXML2.IXMLHTTPRequest xhr1, out MSXML2.IXMLHTTPRequest xhr2)  
{  
var t = Type.GetTypeFromCLSID(new  
Guid(“F6D90F16-9C73-11D3-B32E-00C04F990BB4”)); // guid of  
MSXML2.XMLHTTPClass  
xhr1 = Activator.CreateInstance(t) as MSXML2.IXMLHTTPRequest;  
xhr2 = Activator.CreateInstance(t) as MSXML2.IXMLHTTPRequest;  
}  
}

On Wed, Sep 30, 2009 at 12:19 PM, Jimmy S. \<

---

<div class="post-metadata">

**Author:** ![Orion\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/65b543/32.png) [@Orion\_E](https://www.ruby-forum.com/u/Orion_E)\
**Post date:** [September 30, 2009, 1:53am UTC](https://www.ruby-forum.com/t/0-9-1-regression-when-creating-system-array-of-clr-enum-values/176391/4 "2009-09-30T01:53:25Z")

</div>

On Wed, Sep 30, 2009 at 12:19 PM, Jimmy S. \<  
removed\_email\_address@domain.invalid\> wrote:

> The error message seems to indicate this is the same issue you had in your  
> “Another 0.9.1 regression” mail.

Really? The repro for this one is really simple and has no COM at all.

C# code:

public enum Fields  
{  
None = 0,  
DBID = 1,  
Name = 2  
}

Ruby code

require ‘scratchdll’  
f = [Fields.DBID, Fields.Name]  
System::Array[Fields].new f

=\>  
System::InvalidCastException: The result type ‘System.Int32’ of the  
dynamic  
binding produced by binder ‘ConvertToFixnumA  
ction @1’ is not compatible with the result type ‘Fields’ expected by  
the  
call site.  
from Microsoft.Scripting.Core:0:in `Bind' from Microsoft.Scripting.Core:0:in`BindCore’

Cheers, Orion

---

<div class="post-metadata">

**Author:** ![Orion\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/65b543/32.png) [@Orion\_E](https://www.ruby-forum.com/u/Orion_E)\
**Post date:** [September 30, 2009, 2:58am UTC](https://www.ruby-forum.com/t/0-9-1-regression-when-creating-system-array-of-clr-enum-values/176391/5 "2009-09-30T02:58:23Z")

</div>

I think we actually already have this reported on CodePlex:

[http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=2490](http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=2490)

Tomas

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Orion E.  
Sent: Tuesday, September 29, 2009 4:52 PM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] 0.9.1 regression when creating  
System::Array of clr enum values

On Wed, Sep 30, 2009 at 12:19 PM, Jimmy S.  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\>  
wrote:

The error message seems to indicate this is the same issue you had in  
your “Another 0.9.1 regression” mail.

Really? The repro for this one is really simple and has no COM at all.

C# code:

public enum Fields  
{  
None = 0,  
DBID = 1,  
Name = 2  
}

Ruby code

require ‘scratchdll’  
f = [Fields.DBID, Fields.Name]  
System::Array[Fields].new f

=\>  
System::InvalidCastException: The result type ‘System.Int32’ of the  
dynamic binding produced by binder ‘ConvertToFixnumA  
ction @1’ is not compatible with the result type ‘Fields’ expected by  
the call site.  
from Microsoft.Scripting.Core:0:in `Bind' from Microsoft.Scripting.Core:0:in `BindCore’

Cheers, Orion
