Our team is happy to announce Dynamic Silverlight (DSL), which integrates our DLR dynamic languages with Silverlight. It requires Silverlight 2, which includes the cross-platform CLR and a set of libraries for rich graphics, media and web programming. It is packaged as a Silverlight extension, which means that it is downloaded in addition to Silverlight on an as-needed basis.
DSL has a runtime and an SDK component. The runtime consists of two assemblies: Microsoft.Scripting.dll, and Microsoft.Scripting.Silverlight.dll. You’ll also need the language assemblies, which are IronRuby.dll and IronRuby.Libraries.dll for Ruby and IronPython.dll and IronPython.Modules.dll for Python. The runtime component is a small additional download. Today, the IronRuby Silverlight runtime is just a 712KB download, which takes less than 5 seconds to download over modern broadband.
There is also an SDK component to DSL. The piece of software that you’ll interact with the most is our local web server called Chiron. Created by John Messerly and Dmitry Robsman, it gives you a very nice interactive development experience using nothing more than your local file system. Let’s take a look at Chiron.[1]
Update: Here’s a link to the download of the Dynamic Silverlight SDK. The dsl.bat file can be found in the \bin directory of the SDK.
Open up a command prompt and ensure that Chiron is on your path:
Next, use our template generator to create a starter IronRuby Dynamic Silverlight project:
You’ll see that we’ve generated a set of starter files for you. To run this app, type chiron /b on your command prompt:
This should bring up a browser window with the current directory’s contents displayed:
If you click on the index.html file, you’ll see that the browser fetches a number of files from the server, and displays our Hello, World message:
Chiron prints a list of files that the browser requested. The interesting file is app.xap. This is the way we package Silverlight components for distribution. It’s just a ZIP file with a different name. To look at its contents, just point your browser at http://localhost:2060/app.xap, and you’ll see that it contains:
This illustrates what Chiron does: it dynamically packages everything that you need to run your DSL application into the XAP and serves it up to your browser. The core DSL runtime pieces and the IronRuby assemblies are in the file, along with all of the other files that we generated in our starter application.
Binaries are listed in the AppManifest.xaml file that Chiron generated for you. You can see how Silverlight 2 boots DSL when you open the file:
The EntryPointAssembly is the DSL ‘shim’ that connects the DLR to Silverlight. The EntryPointType is the name of the type that Silverlight will run when it starts up. DynamicApplication derives from the Silverlight System.Windows.Application type, which defines the Startup event which is used to bootstrap the DLR.
Next, let’s look at index.html. The
Notice the reportErrors = errorLocation parameter. This points to a
This element also has a dependency on error.css to define the formatting for the error messages. I think it’s pretty cool that we were able to use the extensibility mechanisms of Silverlight to inject custom DLR error message formatting into Silverlight.
Next, lets look at app.rb:
You’ll notice that we just run this script and inject our hello world message into the element tree defined by the XAML:
There’s a little bit of magic in layout_root.message.text. The message XAML element is a child of the layout_root element. How does Ruby resolve these references? The answer is found in the required file, Silverlight.rb:
We’re adding a method_missing method to the FrameworkElement class and the SilverlightApplication class. So when we try to retrieve layout_root, it delegates to the SilverlightApplication’s implementation of method_missing. It dynamically invokes the target passed in m, which invokes the generic method_missing method in FrameworkElement. This gives a very natural feel for ‘dotting through’ a set of contained XAML elements, which is largely made possible by the Ruby programming language.
I hope this post gives you a feel for what Silverlight programming from IronRuby looks like. In the next part of this series, we’ll look at how we can build a more sophisticated application that uses network stack, JSON, flickr, and some funky animation as well.
[1] The fine print:
~~There’s still some work that we have left to do before we can push the sources and bits out. The code is baked, but packaging this stuff still takes some time. Check back here on Friday, the day of my talk at MIX (you are going, right?), and you’ll have some bits that you can use to follow along with this tutorial~~.
Update: Here’s a link to the download of the Dynamic Silverlight SDK.
You’ll also need to have a working install of CRuby to run some of our utilities. I recommend the Ruby one-click installer for Windows. This will be fixed in the next release of IronRuby.













45 archived reader comments
Timothy (2008-03-05)
This is really cool. But it’s hard to see it as a general solution if it doesn’t run on Macs and Linux. I can see how it could work in a controlled environment, but in my case I can’t depend on my users having PCs.
Is this a technology that is destined to stay on PCs only? Or is there a plan to move it to Mac and Linux as well?
Thibaut Assus (2008-03-05)
Really awesone, but I respect you man, using the poor power shell, instead of a more powerful shell (zsh, bash, etc.), with cygwin.
Michael Letterle (2008-03-05)
@Timothy What makes you think this is PC only? IronRuby runs on Mono… John’s very first paragraph uses the phrase “cross-platform”… ?
Timothy (2008-03-05)
I guess it was the runtime dlls that made me think this is currently PC-only. Is that only for the development environment, or for deployment to browsers?
So this all works now on all platforms?
A screenshot in Camino instead of IE would have convinced me. :-)
Michael Letterle (2008-03-05)
Mono uses the same PE format as the .NET CLR… so you can have dlls that run on both windows and linux/Mac ;)
bryanl (2008-03-05)
Cool.
I wish you could of called it something besides DSL.
John Lam (2008-03-05)
@Timothy:
Dynamic Silverlight should just run on Moonlight modulo bugs / missing features. Debugging is something that I *know* works under IE and even that literally just got working reliably two days ago. So, that’s life on the bleeding edge right now :)
We will work with Miguel’s team to make sure that our stuff just runs on Moonlight. Chiron is a fully managed app that should just run under the desktop Mono stack.
Once we get our bits out at the end of this week, feel free to start opening bugs on our Mono support :)
Timothy (2008-03-05)
OK. If it works across browsers and platforms then it’s worth a trial run for me.
Christopher Bennage (2008-03-05)
This is really cool stuff. I can’t wait to get my hands on this on Friday!
Shimon Amit (2008-03-06)
@Michael Letterle:
I’ll second that. DSL is too confusing (see Domain Specific Languages).
Jason Follas (2008-03-06)
+1. No more ambiguous TLA overloading, please!
“DSL” already has a meaning that plays into DLR and the whole concept of rolling your own language: Domain Specific Language
Jimmy Schementi (2008-03-06)
John just called it “DSL” to put a simpler name for the integration between Silverlight and Dynamic Languages; there’s no “real” name for it … it’s just all Silverlight.
Michael Letterle (2008-03-06)
I vote for DWPF/E!
Actually DSlt.... then you could call it Dee-slight....
Bah, whatever… tell me the first release of Chiron will be called Chiron Beta Prime!
Is it just me or do I feel a slight Rails/WEBrick influence?
Judah Himango (2008-03-06)
John, I mentioned your blog post on CodeProject: http://www.codeproject.com/script/Forums/View.aspx?fid=1159&msg=2453462
And one of the regulars there was outraged that your simple Hellow World app requires 700K. What would you say to that?
KKI (2008-03-06)
In the case of Mac OS X and Linux, because httpd has already been installed, the Chiron.exe is unnecessary, I guess. However, it is necessary to add some MIME setting to execute the app.xap . See Chiron.exe.config in Silverlight SDK.
John Lam (2008-03-06)
@Judah: Depending on how you configure your app, you can download the DSL dependencies (DLR + IronRuby) in a separate XAP that comes from one of our servers (this isn’t working yet). So your XAP becomes something like 2K in that case. It will also be cached in your browser cache so it is a one-time download. Compare with any of the other binary redists of Ruby 1.8.6 for size …
KKI (2008-03-06)
Hi John,
really? It does not work because of the cross domain limitation, I guess.
KKI (2008-03-06)
Sorry, I just noticed the following URL. http://msdn2.microsoft.com/en-us/library/cc197955(VS.95).aspx
Judah Himango (2008-03-07)
Excellent, John, thanks for the info. I’ll let the guy from CodeProject know.
Great job on getting IronRuby running in the browser! Really looking forward to experimenting with this.
Tim (2008-03-07)
You are missing some steps in this presentation:
You jump from verifying that Chiron is in your path to invoking the template generator. Your screen shot shows a >> prompt. What CLI, shell, or app is generating this?
Where is the “dsl” template generator located?
I have seem several demos of the DLR console that show Ruby, Python, and JScript yet there does not seem to be a version available. Where can I find this?
Ivan Porto Carrero (2008-03-08)
In case anybody is wondering how to customize your powershell prompt to look like John’s. Create a directory WindowsPowerShell in My Documents and put a file profile1.ps in there with the following content:
function prompt { $host.ui.rawui.WindowTitle = $(get-location) Write-Host (“+ ” + $(get-location)) -foregroundcolor Yellow return “» ” }
francois (2008-03-09)
Looks very interesting. Unfortunately like Tim I’m stuck at:
”“” Next, use our template generator to create a starter IronRuby Dynamic Silverlight project: “”” It would be useful to have some lights on this.
Thanks.
John Lam (2008-03-09)
@francois: hang in there. Will upload new templates later tonight.
Joe OBrien (2008-03-14)
John,
I love what you have done and all that you are doing to help the Ruby community run on the MS platform (it can only help us in the end).
Being a big proponent of Ruby though, I’m wondering why you guys decided to latch onto the DSL acronym. I know that with all TLA’s you have a chance of tripping over another one; however, with Ruby this seems more serious. One of the benefits of using Ruby (IMHO) is the ability to create DSL’s (as in Domain Specific Languages) to not only aid development, but communication in code.
-Joe
Roel van der Hoorn (2008-03-16)
I found a bug in either IronRuby or Silverlight, but am not sure where to put it, so here it goes:
When you require files from a subdir in app.rb, the
use_xamlexpression afterwards fails with the message ‘XamlParseException: [Line: 0 Position: 0]A workaround is to do another require in your current app-dir and then the error message suddenly dissapears. Very odd.
paul van brenk (2008-03-18)
Where can I find the dsl.rb template, since it doesn’t seem to be included in the SDK or in the rubyforge repository?
ChessMess (2008-03-24)
Ditto others about producing the template. I tried to figure it out but no go. DSL generator is a big ???. The concept of writing Ruby in Silverlight is what has made me interested in Silverlight. But so far its a dead end. Maybe I should just bite the bullet and learn Actionscript 3.
John Lam (2008-03-25)
@{paul,chessmess} you can find the template in the DynamicSilverlight SDK at http://www.dynamicsilverlight.net
Daryn (2008-03-26)
I have having some trouble getting started. This is the problematic step: “Next, use our template generator to create a starter IronRuby Dynamic Silverlight project.”
Where dose the dsl.rb file come from? How can I call this from a standard command prompt? I have Chiron and Ruby in my class path, not sure how to progress? Thanks
John Lam (2008-03-26)
@daryn: the file lives in the \bin directory of the dynamicsilverlight SDK.
Inferis (2008-03-27)
@John: the file isn’t there. I’ve tried downloading both the sdk from the location you specified in your post above, as from the codeplex site. In both cases, no dsl.rb in the \bin directory. All there is are a bunch of .dlls and chiron.exe (and a readme).
Any clues?
Jimmy Schementi (2008-04-03)
All,
dsl.rb isn’t shipped in DynamicSilverlight yet, it’s a small ruby script that simply spits a template file structure; you can achieve the same file structure by just using the
hello_worldsample found in samples/ruby/hello_worldas a starting point. I didn’t tell John that it wouldn’t ship in our package, so it’s my fault =PIf you guys really want the script to do that for you, I can add it to dynamicsilverlight.zip for you.
Jimmy Schementi (2008-04-03)
@Roel:
use_xamlis a helper method to load an associated xaml file for you automatically from a class which inherits from SilverlightApplication.use_xamllives in Silverlight.rb, so feel free to change it … and let me know what fixes you do to fix your bug.I always use it from app.rb like this:
class App < SilverlightApplication
use_xamlendzazi (2008-04-29)
Hey Jimmy, that would maybe very cool if add the dsl.rb to the project, because it generates a little bit confusion at my side to get the example started.
thank a lot,
zazi
Unni (2008-05-04)
Will the dsl.rb included?
Nair (2008-05-05)
Question, is it only few controls are wired to work with Ironruby or all of WPF/E controls are enabled? I tried some different panels and other controls like check box etc., aren’t working. Just curious.
John Lam (2008-05-06)
If you look at silverlight.rb, you’ll see that I’ve only wrapped a few controls and properties.
Sean Clark Hess (2008-07-28)
Tutorial - Develop Silverlight with Ruby on Mac OS X or Linux with the DLR SDK and a Text Editor (TextMate)
http://code.steelpotato.com/2008/07/tutorial-develop-silverlight-with-ruby.html
I updated the tutorial for Silverlight 2 Beta 2, and explain how to set up your system to follow John Lam’s tutorial on Linux or OS X
NO LIGHT IN SIGHT (2009-02-03)
I’ve been trying hard to get the ‘Hello World’ app to work, but no luck.
I get the icon, ‘get Microsoft Silverlight’.
What gives. When I launch localhost:2060 on my application directory, I click index.html. I believe this should take me to my app. I copied all the dlls from /Program Files/Microsoft Silverlight/2* into my chiron/bin directory just to ensure that there were no problems with my path.
Sorry if this question is dumb, but after struggling for several days, I had to seek professional help :(
Jimmy Schementi (2009-02-04)
@”NO LIGHT IN SIGHT”
Did you download the latest release from http://codeplex.com/sdlsdk? The other steps you describe are correct, but you definitely shouldn’t copy files from Program Files, as they will never be loaded, only things in AppManifest.xaml are loaded.
If you’re getting the “Get Microsoft Silverlight” image, please make sure you have the latest version of Silverlight installed.
If you are still having this problem, please open a defect on http://codeplex.com/sdlsdk, with your app attached.
drozzy (2009-11-05)
Link is dead: http://dynamicsilverlight.net/dynamic-silverlight.zip
drozzy (2009-11-05)
This post is so outdated. Not only are the links now dead and irrelavant, it seems the whole nature of the project has changed, with the introduction of ironpython and ironruby?
This is very confusing because this blog post is the official “tutorial” on the Dynamic Languages section of the Silverlight section on microsoft site: http://silverlight.net/learn/dynamic-languages/
Well, another fail there, just as I expected. Time to get back to real web-development with python and django.
drozzy (2009-11-05)
“dsl.rb isn’t shipped in DynamicSilverlight yet”
Wow perhaps you should have started your post with that. M… key
drozzy (2009/11/05)
Link is dead: <a href="http://dynamicsilverlight.net/dynamic-silverlight.zip" rel="nofollow">http://dynamicsilverlight.net/dynamic-silverlight.zip</a>
drozzy (2009/11/05)
"dsl.rb isn’t shipped in DynamicSilverlight yet" Wow perhaps you should have started your post with that. M… key