# Using Local Variable in Silverlight

**URL:** <https://www.ruby-forum.com/t/using-local-variable-in-silverlight/143009>\
**Category:** IronRuby\
**Created:** [July 14, 2008, 1:50pm UTC](https://www.ruby-forum.com/t/using-local-variable-in-silverlight/143009 "2008-07-14T13:50:13Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [July 14, 2008, 1:50pm UTC](https://www.ruby-forum.com/t/using-local-variable-in-silverlight/143009/1 "2008-07-14T13:50:13Z")

</div>

Hi All,

I’m getting an exception when I try and use the code snippet below in  
Silverlight. The snippet works ok with a normal .Net app.

What I am trying to do is use a Ruby script running in my Silverlight  
app to call a method that updates the text on a text block.

public delegate void LogMessageDelegate(string message);

public partial class Page : UserControl  
{  
…

private void RunScript(object sender, System.Windows.RoutedEventArgs  
e)  
{  
ScriptHelper scriptHelper = new ScriptHelper(WriteDebugMessage);

```
ScriptScope scriptScope =

```

IronRuby.CreateRuntime().CreateScope(“IronRuby”);  
scriptScope.SetVariable(“sys”, scriptHelper);  
scriptScope.Execute(“sys.Log(“hello world”)”);  
}

private void WriteDebugMessage(string message)  
{  
m\_scriptDebugText.Text = message; // m\_scriptDebugText is a text  
block.  
}  
}

public class ScriptHelper  
{  
private event LogMessageDelegate m\_logMessage;

public ScriptHelper(LogMessageDelegate logMessage)  
{  
m\_logMessage = logMessage;  
}

public void Log(string message)  
{  
m\_logMessage(message);  
}  
}

The exception I get back is:

“Ruby.Runtime.RubyTopLevelScope.TopMethodMissing(Microsoft.Scripting.Runtime.CodeContext,  
System.Object, Ruby.Runtime.BlockParam, Microsoft.Scripting.SymbolId,  
System.Object[])”

Is there a better approach to interacting between Silverlight UI  
elements and the Ruby script? I’m not using any HTML as the whole  
interface is built of SilverLight controls.

Regards,

Aaron

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [July 14, 2008, 6:48pm UTC](https://www.ruby-forum.com/t/using-local-variable-in-silverlight/143009/2 "2008-07-14T18:48:58Z")

</div>

What’s the exception type and message? Could you please file this as a  
bug?  
It seems it should just work.

Tomas

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [July 15, 2008, 10:48am UTC](https://www.ruby-forum.com/t/using-local-variable-in-silverlight/143009/3 "2008-07-15T10:48:37Z")

</div>

Tomas M. wrote:

> What’s the exception type and message?

The exception type is MethodAccessException and the message is:

“Ruby.Runtime.RubyTopLevelScope.TopMethodMissing(Microsoft.Scripting.Runtime.CodeContext,  
System.Object, Ruby.Runtime.BlockParam, Microsoft.Scripting.SymbolId,  
System.Object)”

> Could you please file this as a bug?

I submitted a bug report on the RubyForge site but is hasn’t shown up.  
Hopefully that’s just to do with it ebing moderated.

The original code snippet works if changed to:

ScriptScope scriptScope =  
IronRuby.CreateRuntime().CreateScope(“IronPython”);  
or  
ScriptScope scriptScope =  
IronRuby.CreateRuntime().CreateScope(“jscript”);

Regards,

Aaron

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [July 18, 2008, 3:28am UTC](https://www.ruby-forum.com/t/using-local-variable-in-silverlight/143009/4 "2008-07-18T03:28:49Z")

</div>

Oh, I know what this is. Could you verify that the method is internal in  
the bits you’re using?  
The method should be public and it is in the current code.

Tomas

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [July 18, 2008, 8:21am UTC](https://www.ruby-forum.com/t/using-local-variable-in-silverlight/143009/5 "2008-07-18T08:21:53Z")

</div>

No, I mean: Ruby.Runtime.RubyTopLevelScope.TopMethodMissing.

I’m not sure you can build successfully against Silverlight. There might  
have been some changes in Silverlight that required us to change  
DLR/IronRuby code since the last public release.

Tomas

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [July 18, 2008, 7:32am UTC](https://www.ruby-forum.com/t/using-local-variable-in-silverlight/143009/6 "2008-07-18T07:32:05Z")

</div>

Tomas M. wrote:

> Oh, I know what this is. Could you verify that the method is internal in  
> the bits you’re using?  
> The method should be public and it is in the current code.
> 
> Tomas

Hi Tomas,

Do you mean the CreateScope method, i.e.  
IronRuby.CreateRuntime().CreateScope(“IronRuby”)?

I was using the IronRuby version from the Silverlight DLR SDK on  
[Your request has been blocked. This could be due to several reasons.](http://www.codeplex.com/sdlsdk) release id 14254. I don’t think the  
method CreateScope could have been internal as I wouldn’t have been able  
to call it?

I did attempt to build the IronRuby code from svn with the SILVERLIGHT  
pre-compilation option sent but got a fair few errors so tried the SDK  
version instead. I’ll give building from SVN another attempt.

Regards,

Aaron

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [July 18, 2008, 10:42am UTC](https://www.ruby-forum.com/t/using-local-variable-in-silverlight/143009/7 "2008-07-18T10:42:43Z")

</div>

Tomas M. wrote:

> No, I mean: Ruby.Runtime.RubyTopLevelScope.TopMethodMissing.
> 
> I’m not sure you can build successfully against Silverlight. There might  
> have been some changes in Silverlight that required us to change  
> DLR/IronRuby code since the last public release.
> 
> Tomas

Hi Tomas,

I’ve checked and you are correct  
Ruby.Runtime.RubyTopLevelScope.TopMethodMissing is static internal .

Any idea when the next IronRuby DLR release is likely to be? I can get  
by with using JScript within Silverlight for the time being.

Thanks,

Aaron

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [July 18, 2008, 11:32am UTC](https://www.ruby-forum.com/t/using-local-variable-in-silverlight/143009/8 "2008-07-18T11:32:17Z")

</div>

DevHawk wrote in his blog  
([http://devhawk.net/2008/07/17/IronPython+Post+20+Roadmap.aspx](http://devhawk.net/2008/07/17/IronPython+Post+20+Roadmap.aspx)):

“Besides IPy 2.1 and 3.0, the other major thing we’re working on is  
Visual Studio integration for IronPython … … (it would be  
nice if IronRuby could leverage our efforts down the road). Like  
everything else we do in this group, we’ll be publishing the VS  
Integration source code up on CodePlex as early and often as we can.”

Are there any plans for a similar VS integration for IronRuby?

/Johan

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [July 18, 2008, 6:28pm UTC](https://www.ruby-forum.com/t/using-local-variable-in-silverlight/143009/9 "2008-07-18T18:28:10Z")

</div>

Yes and as we are in a planning stage, we are extremely eager to hear  
what do you guys think about IronRuby VS integration.  
What features you need, how does it need to look and feel? Don’t  
hesitate to express your thoughts on this subject. We want to make it  
useful and so need to know what do you want and expect.

## VS integration is going to be open source like IronRuby itself and I also hope we will be able to accept contributions into it too.

Oleg

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [July 18, 2008, 3:24pm UTC](https://www.ruby-forum.com/t/using-local-variable-in-silverlight/143009/10 "2008-07-18T15:24:13Z")

</div>

Yes.
