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

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 + “.”



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#

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

dynamic msg = new ExpandoObject();

msg.x = 1;

msg.y = 2;


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.

Answered your question over on StackOverflow:,
Tomas fixed this, and if you build from source now, your code will work.
Best Regards,
Kevin R.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs