Introducing COM Automation in Silverlight 4


In April 2010 Silverlight 4 was released to the world with one of it's greatest features ever, COM-automation support, that allows you to create cutting-edge applications that do everything you can imagine.

What is COM

COM (Common Object Model) is a Microsoft technology introduced in 1993 and currently used by many programming languages (including C++ and VB6) for developing and building software components. Simply, you can think about COM as the counterpart for .NET assemblies in languages like C++ and VB6, .NET assemblies hold program objects and so do COM components, there're many differences of course and one of them is that COM components are much more capable than .NET assemblies and that is what makes accessing them a great improvement to Silverlight.

Today there are many COM components available; Microsoft Office is an example of a COM-based SDK, lots of Windows features are introduced through COM interfaces (Text-to-Speech is a good example,) and lots of 3rd party software (e.g. Adobe Reader) expose their functionalities through COM-based interfaces. Thus, you can't leave COM automation behind if you're willing to create cutting-edge Silverlight applications that do almost everything.

Silverlight OOB Applications


Another great improvement to Silverlight over Adobe Flash is its support for installing and running offline as a desktop application with no network presence. Those Silverlight desktop clients are described as OOB (Out-of-Browser) applications and they have been introduced in Silverlight 3 and extended their functionalities in version 4.


OOB applications are sophisticated desktop clients that can run on any platform with no such code changes required. WPF applications are much capable of course but they support only the Windows platform.

Notice that COM is a Microsoft technology that won't run in a non-Windows machine.

Silverlight 4 and COM


Starting from version 4, you have the ability to call COM-components through your Silverlight application with a small amount of simple and clear code. But don't expect much, you are still constrained by two security restrictions:

  1. Your application needs to be running OOB.
  2. Your application must have the Elevated Trust.

Both requirements are as easy as two mouse clicks; you simply set application requirements in project properties.

Programmatically, to start communicating with a COM component you make use of the AutomationFactory class found in the namespace System.Runtime.InteropServices.Automation (which exist in the main System.Windows.dll). Combine the AutomationFactory class with dynamic coding (and the dynamic keyword) and you can create your COM objects in Silverlight and play with it.

In the next few lessons we'll discuss Silverlight COM automation in details and see it in action though many useful examples that will move your application to infinity. Enjoy!

Up Next
    Ebook Download
    View all
    Learn
    View all