# IronRuby & DynamicObject.TryGetMember returning null

**URL:** <https://www.ruby-forum.com/t/ironruby-dynamicobject-trygetmember-returning-null/211624>\
**Category:** IronRuby\
**Created:** [September 9, 2011, 8:45am UTC](https://www.ruby-forum.com/t/ironruby-dynamicobject-trygetmember-returning-null/211624 "2011-09-09T08:45:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [September 9, 2011, 8:45am UTC](https://www.ruby-forum.com/t/ironruby-dynamicobject-trygetmember-returning-null/211624/1 "2011-09-09T08:45:02Z")

</div>

I am working with IronRuby and a DynamicObject derived class to create a  
proxy layer for a game scripting engine that allows me to intercept gets  
and sets and do things like mark objects for saving, potentially  
security checks, etc.

But I’m finding that if my TryGetMember returns true, but sets the out  
result param to null, then IronRuby seems to hang indefinitely.

I’ve created a pretty concise repro case here:

> <https://gist.github.com/bennidhamma/1205629>

can anyone shed some insight into this problem? So far, I’m loving  
IronRuby.

best,

–ben joldersma

---

<div class="post-metadata">

**Author:** ![dezer85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/57b2e6/32.png) [@dezer85](https://www.ruby-forum.com/u/dezer85)\
**Post date:** [September 9, 2011, 9:03am UTC](https://www.ruby-forum.com/t/ironruby-dynamicobject-trygetmember-returning-null/211624/2 "2011-09-09T09:03:22Z")

</div>

Heads up, looks like this applies to the Expando object as well, here’s  
an even simpler gist:

> <https://gist.github.com/bennidhamma/1205646>

---

<div class="post-metadata">

**Author:** ![dezer85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/57b2e6/32.png) [@dezer85](https://www.ruby-forum.com/u/dezer85)\
**Post date:** [September 9, 2011, 11:13am UTC](https://www.ruby-forum.com/t/ironruby-dynamicobject-trygetmember-returning-null/211624/3 "2011-09-09T11:13:56Z")

</div>

Try implementing TryInvokeMember.

In IronRuby “d.foo” actually gets and invokes “foo”, so it will use  
DynamicObject’s TryInvokeMember. This is different from IronPython and  
C# where method calls are two operations: TryGetMember (d.Foo) and  
TryInvoke (d.Foo()). The rough IronRuby equivalent to this is  
d.method(:foo).call().

~js

---

<div class="post-metadata">

**Author:** ![dezer85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/57b2e6/32.png) [@dezer85](https://www.ruby-forum.com/u/dezer85)\
**Post date:** [September 10, 2011, 2:44am UTC](https://www.ruby-forum.com/t/ironruby-dynamicobject-trygetmember-returning-null/211624/4 "2011-09-10T02:44:27Z")

</div>

Okay, very interesting stuff. I had seen you and others suggest that in  
other places, but I thought I was insulated from it, because I _was_  
implementing TryInvokeMember! After further examination, I seem to have  
stumbled to a solution.

In my actual code, I was trying to return a function delegate in the  
TryGetMember, when the member in question is a method. I think that  
this, coupled with the TryInvokeMember implementation was causing some  
badness. So I removed the delegate creation code in TryGetMember, and  
just handle properties, and then in TryInvokeMember, I handle both  
methods and properties (this seems to work!)

Thanks a million for your help!

Next problem: I’m hesitant to bring it up again, maybe I should be able  
to figure this out on my own, but it’s stumped me for quite a spell now.  
I’m getting a System.InvalidOperationException that says “No coercion  
operator is defined between types ‘System.String’ and  
‘IronRuby.Builtins.MutableString’” when I try and call a method on one  
of my dynamic objects with a literal Ruby string.

I’ve created another gist that reproduces the problem here:

> <https://gist.github.com/bennidhamma/1207726>

If I write ‘test’.to\_clr\_string, this works, but that seems like kind of  
a pain to have to do in my scripts…

Any ideas about this? The difficult part about it is that it doesn’t  
even seem the runtime even gets to the point where any of my overrides  
are executed - no breakpoints are hit in MonoDevelop, no console output,  
so I don’t think I can fix it from that vantage point… Any help is  
much appreciated.

best,

–ben
