You are reading a MIX Online Opinion. In which we speak our minds. Hans Hugli Meet Hans Arrow

Lab Notes

4Comment Retweet

Gestalt Consuming External Assemblies

Mar 31, 2010 In Development By Hans Hugli

Gestalt, the union of the Dynamic Language Runtime and Silverlight, enables writing Rich Internet Applications directly in HTML with Ruby/Python + XAML. Gestalt can call out to external assemblies that exist as loose files or are contained in zip files, which are treated as mini file systems by the DLR. We’ve had some inquires about this feature from our readers, so I thought it was worth calling out.

Ashish Ghoda has put together a fantastic Ruby sample (requires Silverlight to be installed) and an accompanying MSDN article that illustrates just this feature.

Ashish's Silverlight Map Sample

What does this mean for you?

What does being able to call out to external assemblies enable? It gives Gestalt the ability to consume third party written controls and libraries contained in assemblies in an easy and elegant way. XAML fragments can now include the namespaces of controls that are defined in those external assemblies. Additionally, code defined in libraries can be called directly from Ruby or Python, which gives Gestalt access to code that executes with the high performance of static code.

I recommend you take a look at Jimmy Schementi’s session (27 minutes in), in which he talks about this in some detail.

Examining the Sample

I want to take a 10,000 ft. look at Ashish’s sample from the perspective of calling out to external DLL’s. contains Microsoft.Maps.MapControl.dll and Microsoft.Maps.MapControl.Common.dll. By adding a reference to the file, as in the following, the DLR becomes aware of the files that are contained within that ZIP file:

<script src="dlr-20100305.js" type="text/javascript"></script>

<script type="application/x-zip-compressed" src=""></script>

<script type="application/xml+xaml" src="SilverlightMap.xaml" id="sl_map" Width="1350" Height="575" defer="true"></script>

<script type="application/ruby" src="SilverlightMap.rb" class="sl_map"></script>

Please also note that the “defer” attribute on the XAML file is set to true to prevent the DLR from loading up the XAML immediately. We’ll see why this is necessary in a minute.

We now add a reference to the MapControl in the XAML file by adding a namespace, exactly as you would normally do in XAML.

<UserControl x:Name="silverlight_map"
  <m:Map x:Name="map">
     <PlaneProjection RotationX="-0"

To add a reference to DLL’s in Ruby,we add the following “require” statements to the Ruby file. Notice that the path includes the name of the ZIP file:

require "bingmaps/Microsoft.Maps.MapControl"
require "bingmaps/Microsoft.Maps.MapControl.Common"
include Microsoft::Scripting::Silverlight

The XAML is loaded when the “load_root_visual_from_string” method is executed. We wanted to defer the loading of the XAML so that the namespace contained in the XAML would be recognized. If the DLR had loaded the XAML immediately,we would have gotten an error, since at that point the DLR was not aware of the MapControl dependencies. Adding the “require” statements allowed Silverlight to successfully load the XAML file and resolve the namespace references. The source and binaries for Ashish’s sample are located here.

What’s next?

With its ability to call out to external DLL’s, Gestalt opens up a wide spectrum of capabilities that were difficult, if not impossible, to achieve before.

The only downside of this feature is that utilizing external DLL’s goes against the primary intent of Gestalt — to make all the source viewable to the end user. It’s good to know, however, that there’s an option available for doing so… when it’s your only option.

I’ve been wanting to add smooth streaming support to the Video Widget. The source code for Silverlight smooth streaming support is not available, but there is a DLL that ships with Blend that provides this capability. Being able to call out to an external DLL is exactly what’s needed to be able to add this support!

Follow the Conversation

4 comments so far. You should leave one, too.

deeptechtons said on Apr 1, 2010

that was like so cool , i can right away start using these in my upcoming projects!

Soumow Soumow said on Apr 7, 2010

That''s great! but plz does it work on Windows Phone?

Hans Hugli Hans Hugli said on Apr 7, 2010

Hi @Soumow. That is a good question and honestly I don''t know the answer at present, but I will investigate and let you know my findings.

Hans Hugli Hans Hugli said on Apr 9, 2010

@Soumow, In my initial attempt to run this on the Windows Phone 7 Emulator, it did not work with a simple python sample. Apparently it may work with Ruby though according to Jimmy Schementi, so I am going to try that route.