August 11, 2010

How to load an assembly

When you want to access the class from an assembly you have to load it. For those of you familiar with .net development (Visual Studio) it is the equivalent of adding a reference to an assembly in you project and adding an import statement like this :

imports Microsoft.UpdateServices.Administration

In powershell you do it this way :

[reflection.assembly]::Load("Microsoft.UpdateServices.Administration, Version=3.1.6001.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35")

Please note that you should use the complete assembly display name. You can get all that info (name, version, token) from the GAC (c:\windows\assembly) when you display the properties of an assembly.

You should not use the LoadWithPartialName method, it is obsolete. Read Suzanne Cook's .NET CLR Notes to understand why.

No comments:

Post a Comment