Skip to main content

Microsoft Silverlight

Answered Question Execution JScript in SilverlIght Application using DLRRSS Feed

(0)

darrin_ru
darrin_ru

Member

Member

0 points

5 Posts

Execution JScript in SilverlIght Application using DLR

Hello!
I try to make scriptable application using Silverleght DLR. When I try execute JScript code witch cotains two or more lines of code, execution only first line. For example:
I had Compiled SL application written on С#. Main page contains Label named "lblMessage" and Button with Click event handler.

private void Button_Click(object sender, RoutedEventArgs e)
{
ScriptRuntime
scriptRuntime = ScriptRuntime.Create();
foreach (string name in new string[] { "mscorlib", "System", "System.Windows", "System.Windows.Browser", "System.Net" })
{
scriptRuntime.LoadAssembly(scriptRuntime.Host.PlatformAdaptationLayer.LoadAssembly(name));
}
ScriptEngine scriptEngine = scriptRuntime.GetEngine("js");
ScriptScope baseScope = scriptEngine.CreateScope();
gsFormManager fm = gsApplicationManager.FormManager;
baseScope.SetVariable("lblMessage", lblMessage);
string script = "lblMessage.Text = 'First line of code';\r\n" + "lblMessage.Text = 'Second line of code'"
;
ScriptSource scriptSource = scriptEngine.CreateScriptSourceFromString(script);
CompiledCode compiledCode = scriptSource.Compile();
compiledCode.Execute(baseScope);
}

After execution Label.Text will be equal "First line of code" string.

Why ignored second line of code ?

Thank you.

Jonathan Shen – MSFT
Jonathan...

All-Star

All-Star

24939 points

2,425 Posts

Microsoft
Answered Question

Re: Execution JScript in SilverlIght Application using DLR

Hi Darrin_ru,

Please replace your code with mine and have a test.

            string script = "lblMessage.Text = 'First line of code';\r\n" + "lblMessage.Text = 'Second line of code';";
            ScriptSource scriptSource = scriptEngine.CreateScriptSourceFromString(script, Microsoft.Scripting.SourceCodeKind.Statements);
It works on Silverlight 3.
Best regards,
Jonathan

Jonathan Shen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

darrin_ru
darrin_ru

Member

Member

0 points

5 Posts

Re: Execution JScript in SilverlIght Application using DLR

Thanks! It's work.

coolio
coolio

Member

Member

369 points

114 Posts

Re: Execution JScript in SilverlIght Application using DLR

Hey Jonathan.

I thought the Managed JScript for DLR was dropped? How does this work for SL3?

No more secrets with Silverlight Spy 3

darrin_ru
darrin_ru

Member

Member

0 points

5 Posts

Re: Execution JScript in SilverlIght Application using DLR

It's work with SL3 correctly.

coolio
coolio

Member

Member

369 points

114 Posts

Re: Execution JScript in SilverlIght Application using DLR

Yes, but how? Where do I find the JScript binaries. The current DLR package (http://sdlsdk.codeplex.com/) only contains the IronRuby and IronPython languages.

- koen

No more secrets with Silverlight Spy 3

darrin_ru
darrin_ru

Member

Member

0 points

5 Posts

Re: Execution JScript in SilverlIght Application using DLR

I use libs from 0.4.0 sdk
http://sdlsdk.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=17839
As I understood It's final Microsift release of Managed JScript.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities