[Ironruby-core] How do I pass an ExpandoObject from C# into IronRuby?

Goode, Troy Troy.Goode at nreca.coop
Wed Mar 3 02:14:45 EST 2010

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# code:


dynamic handler = ruby.HandleMoveRequested. at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100303/8a372cef/attachment.html>

More information about the Ironruby-core mailing list