YonF
YonF

Reputation: 651

PowerShell how to add-type from GAC

I try to call Add-Type -AssemblyName myassembly, and myassembly has been registered into GAC, but I always got following error:

Cannot add type. The assembly 'myassembly' could not be found.

I know how to Add-Type from a file location, is there a way to Add-Type from GAC conveniently?

Upvotes: 2

Views: 1517

Answers (3)

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41555

To load from the GAC you need the fully qualified assembly name:

Add-Type -AssemblyName "Microsoft.Web.Deployment, Version=9.0.0.0", Colture=netural, PublicKeyToken=89956cdc9090cc76"

And yea, it's really annoying!

Upvotes: 3

js2010
js2010

Reputation: 27423

If you copy it to another computer, you have to unblock it.

Upvotes: 0

StephenP
StephenP

Reputation: 4081

You can also use [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.Web.Deployment') Yes I know its obsolete and you should use Load().

Often you may not have the full name and don't care to enumerate the assemblies in the GAC. This will allow you to load the assembly. If you care, you can then pull the fullname to use with Load() for your scripts going forward.

[System.Reflection.Assembly]::LoadWithPartialName('system.web.security')
PS c:\> [System.Web.Security.Membership].Assembly.Fullname
System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Upvotes: 0

Related Questions