Sunday, May 11, 2008

Assemblies in the Silverlight Runtime

Note:
  • Details in this post apply to Silverlight 2 Beta 1, and may change in future Silverlight versions.
  • You may want to read my previous post to get a better understanding this post.

Say you have a Silverlight application with a Canvas and a ListBox. Both these controls belong to the same namespace System.Windows.Controls. Will these controls be downloaded as part of this particular application's xap, or will this be part of the Silverlight runtime installed initially by the user?

The answer is interesting: As far as Silverlight 2 Beta 1 is concerned, the Canvas is within the System.Windows.dll which is part of the Silverlight runtime and hence will not be downloaded to the client along with the xap. However, the ListBox is within the System.Windows.Controls.dll which is not included in the Silverlight runtime. So this will be downloaded with the xap package.

This also means that if you are creating a custom splash screen then you can use the Canvas within it, but not the ListBox since the splash screen will show before the xap has been downloaded.

Friday, May 9, 2008

Namespaces and Assembly Names

Note: Details in this post apply to Silverlight 2 Beta 1, and may change in future Silverlight versions. The basic idea though remains the same.

A Silverlight developer recently reported this problem. He wanted to use the Silverlight DataGrid in his application. He knew that the DataGrid is a part of the assembly System.Windows.Controls.Data.dll. So he added a reference to this assembly in his Silverlight project. So far so good.

Next he tried to import the namespace by typing in "using System.Windows.Controls.Data" so that he could start using the DataGrid. Now here started the problem. Visual Studio refused to recognize this namespace. Was this a bug in Silverlight, or perhaps in Visual Studio?

Neither. It is true that the DataGrid resides in the assembly System.Windows.Controls.Data.dll; but it is still part of the SystemWindows.Controls namespace just like the other controls in Silverlight.

Let us look at some other examples. The TextBlock, Canvas and Grid too belong to the System.Windows.Controls namespace but they actually reside in the assembly SystemWindows.dll not in SystemWindows.Controls.dll.

By the way, the ListBox is one control that belongs to the namespace System.Windows.Controls and resides in an assembly with the same name.

Simple, but interesting , huh?