# Force a .NET cast (COM Interop)

**URL:** <https://www.ruby-forum.com/t/force-a-net-cast-com-interop/164016>\
**Category:** IronRuby\
**Created:** [March 26, 2009, 11:22pm UTC](https://www.ruby-forum.com/t/force-a-net-cast-com-interop/164016 "2009-03-26T23:22:31Z")\
**Posts on this page:** 3\
**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:22pm UTC](https://www.ruby-forum.com/t/force-a-net-cast-com-interop/164016/1 "2009-03-26T23:22:31Z")

</div>

I have an Interop’ed COM object (System.\_\_ComObject) that I’m trying to  
use  
from an IronRuby script.  
Because the way that you seem to QueryInterface from .NET is to use  
casting,  
I therefore need to cast from within IronRuby.

Basically:

comobject = Activator.create\_instance(base\_com\_type) # returns a base  
type  
which is IUnknown + not much else  
comobject.do\_stuff # throws NoMethodError.

In C#, I’d then do ((ICanDoStuff)comObject).do\_stuff; which calls  
QueryInterface, so the do\_stuff method will now actually exist.

Is there any way I can do this?

---

<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:36pm UTC](https://www.ruby-forum.com/t/force-a-net-cast-com-interop/164016/2 "2009-03-26T23:36:36Z")

</div>

Does the COM object implement IDispatch?

Does the DLR / IronRuby invoke operations against IDispatch  
automagically?

2009/3/26 Orion E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<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:58pm UTC](https://www.ruby-forum.com/t/force-a-net-cast-com-interop/164016/3 "2009-03-26T23:58:51Z")

</div>

I’m not using IDispatch here. These are all statically generated proxy  
classes from some custom C++ COM Interfaces.  
Hopefully if I can get casting to work, I’ll be good to go

2009/3/27 Brannon J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
