Reputation: 651
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
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
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