Ivan Porto Carrero
2009-Nov-25 13:29 UTC
[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 Carrero
Blog: http://flanders.co.nz
Google Wave: portocarrero.ivan at googlewave.com
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/ironruby-core/attachments/20091125/0b9739bc/attachment.html>
Tomas Matousek
2009-Nov-25 17:16 UTC
[Ironruby-core] invoke member and dynamic binding isn''t the same?
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: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at
rubyforge.org] 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 Carrero
Blog: http://flanders.co.nz
Google Wave: portocarrero.ivan at googlewave.com<mailto:portocarrero.ivan at
googlewave.com>
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/ironruby-core/attachments/20091125/cfbe47fe/attachment-0001.html>
Ivan Porto Carrero
2009-Nov-30 09:08 UTC
[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 --- Met vriendelijke groeten - Best regards - Salutations Ivan Porto Carrero Blog: http://flanders.co.nz Google Wave: portocarrero.ivan at googlewave.com Twitter: http://twitter.com/casualjim Author of IronRuby in Action (http://manning.com/carrero) On Wed, Nov 25, 2009 at 6:16 PM, Tomas Matousek < Tomas.Matousek at microsoft.com> 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:* ironruby-core-bounces at rubyforge.org [mailto: > ironruby-core-bounces at rubyforge.org] *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 Carrero > Blog: http://flanders.co.nz > Google Wave: portocarrero.ivan at googlewave.com > Twitter: http://twitter.com/casualjim > Author of IronRuby in Action (http://manning.com/carrero) > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20091130/321a7b47/attachment.html>
Tomas Matousek
2009-Nov-30 19:20 UTC
[Ironruby-core] invoke member and dynamic binding isn''t the same?
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
Tomas
From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at
rubyforge.org] On Behalf Of Ivan Porto Carrero
Sent: Monday, November 30, 2009 1:08 AM
To: ironruby-core at rubyforge.org
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
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Google Wave: portocarrero.ivan at googlewave.com<mailto:portocarrero.ivan at
googlewave.com>
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
On Wed, Nov 25, 2009 at 6:16 PM, Tomas Matousek <Tomas.Matousek at
microsoft.com<mailto:Tomas.Matousek at microsoft.com>> 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: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at
rubyforge.org> [mailto:ironruby-core-bounces at
rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org>] 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 Carrero
Blog: http://flanders.co.nz
Google Wave: portocarrero.ivan at googlewave.com<mailto:portocarrero.ivan at
googlewave.com>
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
_______________________________________________
Ironruby-core mailing list
Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org>
http://rubyforge.org/mailman/listinfo/ironruby-core
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/ironruby-core/attachments/20091130/257939ce/attachment-0001.html>
Ivan Porto Carrero
2009-Dec-01 10:02 UTC
[Ironruby-core] invoke member and dynamic binding isn''t the same?
d''oh Indeed after using the correct libraries things do work, imagine that... Thanks. --- Met vriendelijke groeten - Best regards - Salutations Ivan Porto Carrero Blog: http://flanders.co.nz Google Wave: portocarrero.ivan at googlewave.com Twitter: http://twitter.com/casualjim Author of IronRuby in Action (http://manning.com/carrero) On Mon, Nov 30, 2009 at 8:20 PM, Tomas Matousek < Tomas.Matousek at microsoft.com> wrote:> 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 > > > > Tomas > > > > *From:* ironruby-core-bounces at rubyforge.org [mailto: > ironruby-core-bounces at rubyforge.org] *On Behalf Of *Ivan Porto Carrero > *Sent:* Monday, November 30, 2009 1:08 AM > *To:* ironruby-core at rubyforge.org > *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 > --- > Met vriendelijke groeten - Best regards - Salutations > Ivan Porto Carrero > Blog: http://flanders.co.nz > Google Wave: portocarrero.ivan at googlewave.com > Twitter: http://twitter.com/casualjim > Author of IronRuby in Action (http://manning.com/carrero) > > > On Wed, Nov 25, 2009 at 6:16 PM, Tomas Matousek < > Tomas.Matousek at microsoft.com> 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:* ironruby-core-bounces at rubyforge.org [mailto: > ironruby-core-bounces at rubyforge.org] *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 Carrero > Blog: http://flanders.co.nz > Google Wave: portocarrero.ivan at googlewave.com > Twitter: http://twitter.com/casualjim > Author of IronRuby in Action (http://manning.com/carrero) > > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > > > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20091201/3786659e/attachment.html>