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?

No comments: