# Invoke member and dynamic binding isn't the same?

**URL:** <https://www.ruby-forum.com/t/invoke-member-and-dynamic-binding-isnt-the-same/179459>\
**Category:** IronRuby\
**Created:** [November 25, 2009, 2:43pm UTC](https://www.ruby-forum.com/t/invoke-member-and-dynamic-binding-isnt-the-same/179459 "2009-11-25T14:43:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [November 25, 2009, 2:43pm UTC](https://www.ruby-forum.com/t/invoke-member-and-dynamic-binding-isnt-the-same/179459/1 "2009-11-25T14:43:01Z")

</div>

Hi  
I have some ruby code, which through a process of instance\_eval and  
other  
meta programming tricks builds an object with a method assign defined on  
it.

I have this code in C#

_var scope = Engine.CreateScope();_  
_scope.SetVariable(“ctxt”, this);_  
_Engine.ExecuteFile(“rubyfile.rb”, scope);_

This code correctly sets a something property on this (linked with ctxt)  
but when I then want to call a method on it that should exist

_public dynamic Something { get; set; }_

_Something.assign(“ivan”)_

Unhandled Exception:  
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:  
‘Iro  
nRuby.Builtins.RubyObject’ does not contain a definition for ‘assign’  
at CallSite.Target(Closure , CallSite , Object , String )  
at  
System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite  
site,  
T0 arg0, T1 arg1)  
at BugTracker\_40.Bug.Assign(String assignee) in  
C:\dev\ironruby-in-action\Sam  
ples\BugTracker\_40\BugTracker\_40\Bug.cs:line 60  
at BugTracker\_40.Program.Main(String[] args) in  
C:\dev\ironruby-in-action\Sam  
ples\BugTracker\_40\BugTracker\_40\Program.cs:line 13

However the same code with:

var \_rubyOperations = Engine.CreateOperations()  
public object Something { get; set; }  
\_rubyOperations.InvokeMember(Something, “assign”, “ivan”)

does work.

## The question is why? Is this the expected behavior? Am I missing an assembly reference (it has Ironruby.\*, Microsoft.Scripting, Microsoft.Scripting.Core)

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
Blog: [http://flanders.co.nz](http://flanders.co.nz)  
Google Wave: removed\_email\_address@domain.invalid  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)  
Author of IronRuby in Action ([http://manning.com/carrero](http://manning.com/carrero))

---

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [November 25, 2009, 6:27pm UTC](https://www.ruby-forum.com/t/invoke-member-and-dynamic-binding-isnt-the-same/179459/2 "2009-11-25T18:27:12Z")

</div>

Can you send the entire source code that sets â€œSomethingâ€ and then the  
entire C# method that accesses it, ideally a minimal repro?

Tomas

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Ivan Porto  
Carrero  
Sent: Wednesday, November 25, 2009 5:29 AM  
To: ironruby-core  
Subject: [Ironruby-core] invoke member and dynamic binding isn’t the  
same?

Hi  
I have some ruby code, which through a process of instance\_eval and  
other meta programming tricks builds an object with a method assign  
defined on it.

I have this code in C#

var scope = Engine.CreateScope();  
scope.SetVariable(“ctxt”, this);  
Engine.ExecuteFile(“rubyfile.rb”, scope);

This code correctly sets a something property on this (linked with ctxt)  
but when I then want to call a method on it that should exist

public dynamic Something { get; set; }

Something.assign(“ivan”)

Unhandled Exception:  
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ‘Iro  
nRuby.Builtins.RubyObject’ does not contain a definition for ‘assign’  
at CallSite.Target(Closure , CallSite , Object , String )  
at  
System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite  
site,  
T0 arg0, T1 arg1)  
at BugTracker\_40.Bug.Assign(String assignee) in  
C:\dev\ironruby-in-action\Sam  
ples\BugTracker\_40\BugTracker\_40\Bug.cs:line 60  
at BugTracker\_40.Program.Main(String[] args) in  
C:\dev\ironruby-in-action\Sam  
ples\BugTracker\_40\BugTracker\_40\Program.cs:line 13

However the same code with:

var \_rubyOperations = Engine.CreateOperations()  
public object Something { get; set; }  
\_rubyOperations.InvokeMember(Something, “assign”, “ivan”)

does work.

## The question is why? Is this the expected behavior? Am I missing an assembly reference (it has Ironruby.\*, Microsoft.Scripting, Microsoft.Scripting.Core)

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
Blog: [http://flanders.co.nz](http://flanders.co.nz)  
Google Wave:  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)  
Author of IronRuby in Action ([http://manning.com/carrero](http://manning.com/carrero))

---

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [November 30, 2009, 10:08am UTC](https://www.ruby-forum.com/t/invoke-member-and-dynamic-binding-isnt-the-same/179459/3 "2009-11-30T10:08:51Z")

</div>

I’ve included a C# project with all the files you need as attachment.

## [http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=3213](http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=3213)

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
Blog: [http://flanders.co.nz](http://flanders.co.nz)  
Google Wave: removed\_email\_address@domain.invalid  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)  
Author of IronRuby in Action ([http://manning.com/carrero](http://manning.com/carrero))

On Wed, Nov 25, 2009 at 6:16 PM, Tomas M. \<

---

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [December 1, 2009, 11:07am UTC](https://www.ruby-forum.com/t/invoke-member-and-dynamic-binding-isnt-the-same/179459/4 "2009-12-01T11:07:52Z")

</div>

d’oh  
Indeed after using the correct libraries things do work, imagine that…

Thanks.

* * *

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
Blog: [http://flanders.co.nz](http://flanders.co.nz)  
Google Wave: removed\_email\_address@domain.invalid  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)  
Author of IronRuby in Action ([http://manning.com/carrero](http://manning.com/carrero))

On Mon, Nov 30, 2009 at 8:20 PM, Tomas M. \<

---

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [November 30, 2009, 8:21pm UTC](https://www.ruby-forum.com/t/invoke-member-and-dynamic-binding-isnt-the-same/179459/5 "2009-11-30T20:21:08Z")

</div>

It seems that you reference IronRuby binaries built against CLR 2.0. You  
need to use CLR4 binaries:  
[http://ironruby.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=33305](http://ironruby.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=33305)

Tomas

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Ivan Porto  
Carrero  
Sent: Monday, November 30, 2009 1:08 AM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] invoke member and dynamic binding isn’t the  
same?

I’ve included a C# project with all the files you need as attachment.

## [http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=3213](http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=3213)

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
Blog: [http://flanders.co.nz](http://flanders.co.nz)  
Google Wave:  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)  
Author of IronRuby in Action ([http://manning.com/carrero](http://manning.com/carrero))

On Wed, Nov 25, 2009 at 6:16 PM, Tomas M.  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\>  
wrote:  
Can you send the entire source code that sets â€œSomethingâ€ and then the  
entire C# method that accesses it, ideally a minimal repro?

Tomas

From:  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
On Behalf Of Ivan Porto C.  
Sent: Wednesday, November 25, 2009 5:29 AM  
To: ironruby-core  
Subject: [Ironruby-core] invoke member and dynamic binding isn’t the  
same?

Hi  
I have some ruby code, which through a process of instance\_eval and  
other meta programming tricks builds an object with a method assign  
defined on it.

I have this code in C#

var scope = Engine.CreateScope();  
scope.SetVariable(“ctxt”, this);  
Engine.ExecuteFile(“rubyfile.rb”, scope);

This code correctly sets a something property on this (linked with ctxt)  
but when I then want to call a method on it that should exist

public dynamic Something { get; set; }

Something.assign(“ivan”)

Unhandled Exception:  
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ‘Iro  
nRuby.Builtins.RubyObject’ does not contain a definition for ‘assign’  
at CallSite.Target(Closure , CallSite , Object , String )  
at  
System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite  
site,  
T0 arg0, T1 arg1)  
at BugTracker\_40.Bug.Assign(String assignee) in  
C:\dev\ironruby-in-action\Sam  
ples\BugTracker\_40\BugTracker\_40\Bug.cs:line 60  
at BugTracker\_40.Program.Main(String[] args) in  
C:\dev\ironruby-in-action\Sam  
ples\BugTracker\_40\BugTracker\_40\Program.cs:line 13

However the same code with:

var \_rubyOperations = Engine.CreateOperations()  
public object Something { get; set; }  
\_rubyOperations.InvokeMember(Something, “assign”, “ivan”)

does work.

## The question is why? Is this the expected behavior? Am I missing an assembly reference (it has Ironruby.\*, Microsoft.Scripting, Microsoft.Scripting.Core)

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
Blog: [http://flanders.co.nz](http://flanders.co.nz)  
Google Wave:  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)  
Author of IronRuby in Action ([http://manning.com/carrero](http://manning.com/carrero))

* * *

Ironruby-core mailing list  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)
