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: http://blogs.msdn.com/b/clrteam/archive/2009/12/01/sharing-silverlight-assemblies-with-net-apps.aspx

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

Leave a Reply

Your email address will not be published. Required fields are marked *