Close this search box.

Silverlight: Running standalone full trust applications


I guess that it’s time to write about it, after making a few people curious at the MVP summit in Seattle. This article is to be taken as a proof of concept, and (I hope) as a way to “motivate” Microsoft to integrate this ability into Silverlight.

As soon as I started playing with Silverlight, I saw the great potential that this technology has. As a RIA technology, it provides extended functionality over the web. As a WPF subset, it allows me to leverage the knowledge I already acquired in the past, and to reuse it for web applications. This in itself makes Silverlight a technology I *have to* learn.

But what if… what if we could use Silverlight to run lightweight .NET applications in standalone mode? A little like Adobe AIR is offering, but with the power of .NET instead of ActionScript. Imagine a small application, running on a small framework, installed in typically 10 seconds.

I posted an article on my site explaining the thought process and giving information about standalone Silverlight applications, their promises and their limitations. For those of you too impatient to read the full article 🙂 you can download a demo and the source code directly from here.

The demo

o install the demo, follow the steps:

  • Download the Zip file.
  • Extract the Zip file to a folder on your hard drive.
  • On Windows: double-click the file “Start.hta”.

This starts the MSHTA host, and displays the Silverlight application.

Silverlight application in MSHTA

  • Enter a directory path in the first textbox, and then click on “Get list of files”. This displays the corresponding list in the listbox.
  • Select a file. Its name is displayed in the second textbox.
  • You can now modify the file name and press on “Rename”.
  • Enter any file path in the last textbox and press “Does file exist?”. A corresponding message is displayed in the status bar.

This last functionality is also available in Mozilla-based browsers, for example Firefox. You can try it by setting Firefox to be your default browser, and then double-clicking the file “index.html” located in the same folder as “index.hta”. This starts the application in “file” mode, and you get the same permissions. The other functionalities “Get list of files” and “Rename” are not implemented in Firefox and will raise an error.

Silverlight application in Firefox

Source code

As usual, the source code is available for download. It contains the following projects:

  • GalaSoft.SL.TestHta: This is the Silverlight application you want to run. It contains an “index.html” file, which should be the start page if you run the application in “F5” or “Ctrl-F5” mode in Studio. Visual Studio runs the HTML file in file mode, so you get a chance to debug the Silverlight code, but unfortunately it is not possible to debug the JavaScript code. When you build the project, a “index.hta” file is automatically created. This is exactly the same as “index.html”, but with a different extension. Double-clicking this file in Windows Explorer will start the MSHTA host.
  • GalaSoft.SL.IO: This is a library defining a new DirectoryInfo and FileInfo classes. These classes mimic the actual System.IO.DirectoryInfo and System.IO.FileInfo classes. They use the class “GalaSoft.SL.IO.ScriptFacade” to channel the full-trust calls to the script code contained in the file “script\gslb.filesystemexplorer.js”.
  • GalaSoft.SL.IO.Test: A Unit Test application for GalaSoft.SL.IO. Written using the Silverlight Unit Test framework and accessing JavaScript as described here. I use this to unit test all my IO classes and methods, including the corresponding JavaScript file.
    Note: The console application “GalaSoft.SL.IO.Test.Prepare” must be executed before the unit test is run.
  • GalaSoft.SL.IO.Test.Prepare: This console application is needed to create a few directories and files in the local drive in order to unit test the library GalaSoft.SL.IO. It requires write-permission to the folder c:\temp. Unfortunately, I don’t think that Mock frameworks exist for JavaScript yet.

In normal use, the project GalaSoft.SL.TestHta should be chosen as startup project, and its file “index.html” as startup page. You can modify the application code. If you change the HTML code, the changes will automatically be copied to “index.hta” when you build the application.

Components involved in a standalone Silverlight application

This article is part of the GWB Archives. Original Author: Code Trotter

Related Posts