# Casting Objects (COM Interop) addendum

**URL:** <https://www.ruby-forum.com/t/casting-objects-com-interop-addendum/164017>\
**Category:** IronRuby\
**Created:** [March 26, 2009, 11:23pm UTC](https://www.ruby-forum.com/t/casting-objects-com-interop-addendum/164017 "2009-03-26T23:23:06Z")\
**Posts on this page:** 2\
**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:** [March 26, 2009, 11:23pm UTC](https://www.ruby-forum.com/t/casting-objects-com-interop-addendum/164017/1 "2009-03-26T23:23:06Z")

</div>

As a follow up to my last message, I wrote a small util method, as  
follows:  
public static class Util  
{  
public static T Cast(object o)  
{  
return (T)o;  
}  
}

And then try to call it from ruby:

x = Util.method(:cast).of(ICanDoStuff).call(mycomobject)

However, the Util.method(:cast).of(ICanDoStuff) fails with this error:

c:\NB\DLR\18015\Languages\Ruby\Src\IronRuby.Libraries\Protocols.cs:405:in  
`ToType': invalid value for Class: ProxyLi b::ICanDoStuff (ArgumentError) from c:\NB\DLR\18015\Languages\Ruby\Src\IronRuby.Libraries\Protocols.cs:386:in`ToTypes’  
from  
c:\NB\DLR\18015\Languages\Ruby\Src\IronRuby.Libraries\Builtins\MethodOps.cs:75:in  
`BindGenericParameters' from :0:in`of’  
from :0

Util.method(:cast).of(String) works fine however - is this because I’m  
trying to pass in a .NET interface (which lives in an auto-generated  
interop  
dll built by tlbimp) rather than a class?

Any help is much appreciated

---

<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:** [March 26, 2009, 11:29pm UTC](https://www.ruby-forum.com/t/casting-objects-com-interop-addendum/164017/2 "2009-03-26T23:29:32Z")

</div>

COM Interop is not supported in IronRuby. COM objects are not easily  
reflectable. It _can_ be supported. See

> **[Shri Borde's WebLog](https://learn.microsoft.com/en-us/archive/blogs/shrib/)**

for how IronPython does it. However, IronRuby has not done the  
equivalent work yet. We will get to it at some point, but as noted in  
[http://www.ironruby.net/About/Roadmap](http://www.ironruby.net/About/Roadmap), its low priority for now as there  
are more important scenarios we need to nail first.

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Orion E.  
Sent: Thursday, March 26, 2009 3:22 PM  
To: removed\_email\_address@domain.invalid  
Subject: [Ironruby-core] Casting Objects (COM Interop) addendum

As a follow up to my last message, I wrote a small util method, as  
follows:

public static class Util  
{  
public static T Cast(object o)  
{  
return (T)o;  
}  
}

And then try to call it from ruby:

x = Util.method(:cast).of(ICanDoStuff).call(mycomobject)

However, the Util.method(:cast).of(ICanDoStuff) fails with this error:

c:\NB\DLR\18015\Languages\Ruby\Src\IronRuby.Libraries\Protocols.cs:405:in  
`ToType': invalid value for Class: ProxyLi b::ICanDoStuff (ArgumentError) from c:\NB\DLR\18015\Languages\Ruby\Src\IronRuby.Libraries\Protocols.cs:386:in `ToTypes’  
from  
c:\NB\DLR\18015\Languages\Ruby\Src\IronRuby.Libraries\Builtins\MethodOps.cs:75:in  
`BindGenericParameters' from :0:in `of’  
from :0

Util.method(:cast).of(String) works fine however - is this because I’m  
trying to pass in a .NET interface (which lives in an auto-generated  
interop dll built by tlbimp) rather than a class?

Any help is much appreciated
