Silverlight 4 101: Using Silverlight Assemblies in your non-Silverlight Projects

If you’re like me, you have been coding in .NET for a long time (for me, pre-version 1.0) and you have many libraries containing classes you would like to reuse in your Silverlight applications.

However, if you try to reference a non-Silverlight assembly from a Silverlight project, you will get the following error message from Visual Studio:

You can’t add a reference to <assembly name> as it was not built against the Silverlight runtime. Silverlight projects will only work with Silverlight assemblies.

Although you can’t reference a non-Silverlight assembly from a Silverlight project, starting with Silverlight 4 and .NET 4, you CAN go the other way–reference a Silverlight assembly from a non-Silverlight project. This feature is known as “assembly portability”. This portability currently only works with the following Silverlight assemblies:

– Mscorlib
– System
– System.Core
– System.ComponentModel.Composition
– Microsoft.VisualBasic

So, as long as you convert your existing .NET class libraries to Silverlight projects and only referene the above assemblies, you can use these libraries from both Silverlight and non-Silverlight projects.

For more information, check out this CLR Team Blog post:

Best Regards,
Kevin McNeish
INETA Speaker
Chief Software Architect, MM .NET Applicaiton Framework

Silverlight 4 101: Silverlight Project Templates

In Silverlight 4 with Visual Studio 2010, there are five Silverlight project templates to choose from. Here is a summary of each:

Silverlight Application
Creates a blank Silverlight project. After selecting this template, a dialog appears asking you to specify whether you want to host the Silverlight application in a new Web site (either an ASP.NET Web Application Project, ASP.NET Web Site, or an ASP.NET MVC Web Project). You can also specify the Silverlight Version (based on the list of Silverlight SDKs installed on your machine), and whether you want to enable WCF RIA Services (discussed below). This template does not implement the Silverlight Navigation Framework (discussed below).

Silverlight Class Library
Creates an empty class library that can be used from a Silverlight application. When you select this template, a dialog appears asking which version of Silverlight you want to target. The resulting solution contains a single project with a single class definition.

Silverlight Business Application
Creates a project that is set up to use both the Silverlight Navigation Framework (discussed under the next template) as well as RIA Services (discussed under the last template).

Silverlight Navigation Application
Creates a project that uses the Silverlight Navigation Framework ( which allows you to easily navigate between pages in a Silverlight application, as well as interaction with the Browser History journal and provides Uri mapping.

WCF RIA Services Class Library
Creates a solution containing two projects that enable you to create reusable middle-tier and presentation-tier logic. A link exists between the generated Silverlight and middle-tier project that facilitates generating presentation-tier code from middle-tier code. For details, check out this link:

Best Regards,
Kevin McNeish
INETA Speaker
Chief Software Architect, MM .NET Application Framework

Silverlight 4 101: Installing Silverlight

Microsoft releases new versions of Silverlight out of step with the release cycle for Visual Studio, so even if you have the latest updates for Visual Studio installed on your development machine, you still need to go to the Microsoft Silverlight site to download the latest Silverlight bits:

To install Silverlight 4 on your VS 2010 development machine, you can download the installer from this link:

This installer includes the following components:

– Silverlight 4 Developer Runtime
– Silverlight 4 Update for Visual Studio 2010 and Visual Web Developer Express 2010
– Silverlight 4 SDK
– Silverlight 4 Tools Package for Visual Studio 2010
– WCF RIA Services V1.0 for Silverlight 4
– F# Runtime for Silverlight 4

If you have a previous version of Silverlight on your development machine, the installer will also:

– Uninstall Earlier Visual Studio 2010 Update
– Uninstall Earlier WCF RIA Services

Best Regards,
Kevin McNeish
INETA Speaker
Chief Software Architect, MM .NET Application Framework