This page is likely outdated (last edited on 19 Oct 2010). Visit the new documentation for updated content.


As of today, Moonlight’s engine is used in two scenarios:

  • As part of the Moonlight Web Plugin, to render online Silverlight content.
  • As a standalone library to create desktop applications that can use the Silverlight API.

Using the former is discussed extensively on any site that discussed Silverlight development and represents the core of our work.

Table of contents

API differences

While Moonlight on the web exposes the same functionality that Silverlight and uses the same assembly versions, APIs and signatures, the desktop edition is not bound by those requirements.

When you develop applications with Moonlight/Desktop you get access to all of the standard .NET 3.5 APIs that are available in Mono. Think of Moonlight/Desktop as extending your standard .NET developer APIs with the following assemblies:

  • System.Windows.dll
  • System.Windows.Browser.dll
  • System.Windows.Controls.dll
  • System.Windows.Controls.Data.dll

and our Gtk integration library:

  • Moonlight.Gtk.dll

Today Moonlight on the desktop is currently limited to the Gtk+ toolkit as that is the only bridge that we have built, but we expect to create bridges for other toolkits and platforms in the future.

Using Moonlight on the Desktop


Sample Solution Layout

To create desktop applications, create a Gtk# project, and add to your project the following assemblies:

  • System.Windows.dll
  • Moonlight.Gtk.dll

The first assembly contains the Silverlight API, the second contains the glue that hosts your Silverlight content inside a Gtk# application.

The solution should look like the image on the sidebar.

Then, you need to import the namespaces into your application, like this:

using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Moonlight.Gtk;

Then you need to initialized Moonlight, do this by calling MoonlightRuntime.Init(), just after Gtk.Application.Init():

You then need to create a Gtk.Widget that will host your Silverlight control. This is done with the MoonlightHost class, use it like this:

    var host =  new MoonlightHost ();

You can add that to any Gtk.Container, in this case, we will add it to the window:

    window.Add (host);
    window.ShowAll ();

You will want to create your Silverlight components, for example this creates a canvas:

Canvas container = new Canvas (){
    Width = width,
    Height = height,
    Background = new SolidColorBrush (Color.FromArgb (255, 0x4c, 0x4c, 0x4c))

You then must add the canvas into your host, do this with:

 h.Application.RootVisual = container;

The full sample should look like this:

using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Controls;
using Moonlight.Gtk;
namespace SilverDesktop
    class MainClass
        public static void Main (string[] args)
            Gtk.Application.Init ();
            MoonlightRuntime.Init ();
            MainWindow win = new MainWindow ();
            var host = new MoonlightHost ();
            var canvas = new Canvas () {
                Width = 300, Height = 300,
                Background = new SolidColorBrush (Colors.DarkGray)
            host.Application.RootVisual = canvas;
            win.Add (host);
            win.ShowAll ();
            Gtk.Application.Run ();

Setting Moonlight on the Desktop

Ideally, your distribution will have the proper packages for Moonlight on the desktop. If it is not available, you will need to build Mono and Moonlight from source code. The following sections explain how to get this ready.

Verifying Your Installation

You first need to make sure that you have the Moonlight for the desktop libraries installed on your system.

If you are using MonoDevelop To do this, use the following command:

$ pkg-config --modversion silverdesktop

If the result is something like:

Package foo was not found in the pkg-config search path.
Perhaps you should add the directory containing `silverdesktop.pc'
to the PKG_CONFIG_PATH environment variable
No package 'silverdesktop' found

It means that you do not have Moonlight/desktop installed.

Building Moonlight for the Desktop

Building Moonlight

Please carefully read the README file on github for the latest Moonlight build instructions.

Make sure that you pass the flag: –enable-desktop-support to configure, to ensure that the Moonlight Desktop assemblies are compiled.

For private installation use:

cd ../moon
./ --prefix=$HOME/build --enable-desktop-support
make && make install

For a system installation use:

cd ../moon
./ --enable-desktop-support
Password: <enter-your-root-password>
# make install

The output after configuration should look like this:

Moonlight configuration
  Silverlight Support:
    Silverlight 1.0: yes
    Silverlight 2.0: yes
          Browser plugin assemblies: yes
            Path to mcs tree: ./../mcs
            Path to mono-basic tree: ./../mono-basic
          Desktop application assemblies: yes

Using Moonlight on the Desktop - Alternate Prefix

If you chose to install Moonlight in the private prefix instead of the system, you need to set a few environment variables that are required by MonoDevelop to find Moonlight and for the system to find the libraries.

Use these settings in your shell:

export MONO_GAC_PREFIX=/usr:$HOME/build
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$HOME/build/lib/pkgconfig

At that point you can run MonoDevelop and your application, they will automatically pick up your new assemblies.