# How do I pass an ExpandoObject from C# into IronRuby?

**URL:** <https://www.ruby-forum.com/t/how-do-i-pass-an-expandoobject-from-c-into-ironruby/184478>\
**Category:** IronRuby\
**Created:** [March 3, 2010, 8:21am UTC](https://www.ruby-forum.com/t/how-do-i-pass-an-expandoobject-from-c-into-ironruby/184478 "2010-03-03T08:21:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GoodeS\_Troy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@GoodeS\_Troy](https://www.ruby-forum.com/u/GoodeS_Troy)\
**Post date:** [March 3, 2010, 8:21am UTC](https://www.ruby-forum.com/t/how-do-i-pass-an-expandoobject-from-c-into-ironruby/184478/1 "2010-03-03T08:21:28Z")

</div>

I tried to send this question earlier, but it did not appear to go  
through. Shortly after I tried to send it the first time, the “Consuming  
DynamicObjects in IronRuby” thread popped up. It seems likely that the  
two issues are related, but as my situation is a bit different and  
results in a different error message, I thought it would be a good idea  
to resend this question. Note: I am using .Net 4.0 RC and the “CTP for  
.Net 4.0 RC” release of IronRuby…

So I’m finally getting around to testing IronRuby/C# integration and hit  
a stumbling block. Let’s say I have the following class in Ruby:

class HandleMoveRequested

```
            def handle(msg)

                            System::Console.WriteLine "Moving 

```

character to " + msg.x.to\_s + “,” + msg.y.to\_s + “.”

```
            end

```

end

As you can see it is a simple message handler that expects an object  
that has an “x” and a “y” property. Now say I have the following C#  
code:

dynamic handler = ruby.HandleMoveRequested.@new();

dynamic msg = new ExpandoObject();

msg.x = 1;

msg.y = 2;

handler.handle(msg);

Creating the handler instance works fine, so I won’t bore you with the  
details of that, but for some reason the last line throws an  
InvalidOperationException with the message “unbound variable: value”.  
Everything works if the message is a Ruby class that I create manually,  
but I’d love to be able to just create a fully dynamic object (such as  
the ExpandoObject) here and pass it in. Is this just not possible?

Confidentiality Notice: This e-mail message, including any attachments,  
is for the sole use of the intended recipient(s) and may contain  
confidential and privileged information. Any unauthorized review, copy,  
use, disclosure, or distribution is prohibited. If you are not the  
intended recipient, please contact the sender by reply e-mail and  
destroy all copies of the original message.

---

<div class="post-metadata">

**Author:** ![GoodeS\_Troy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@GoodeS\_Troy](https://www.ruby-forum.com/u/GoodeS_Troy)\
**Post date:** [March 3, 2010, 8:24pm UTC](https://www.ruby-forum.com/t/how-do-i-pass-an-expandoobject-from-c-into-ironruby/184478/2 "2010-03-03T20:24:25Z")

</div>

Answered your question over on StackOverflow:

> <https://stackoverflow.com/questions/2365668/how-do-i-pass-an-expandoobject-from-c-into-ironruby>

[http://stackoverflow.com/questions/2365668/how-do-i-pass-an-expandoobject-from-c-into-ironruby/](http://stackoverflow.com/questions/2365668/how-do-i-pass-an-expandoobject-from-c-into-ironruby/)Essentially,  
Tomas fixed this, and if you build from source now, your code will work.  
Thanks  
Best Regards,  
Kevin R.
