powershell: creating a generic hashset with syntax error? -
i tried in powershell 4.0:
[system.assembly]::loadwithpartialname("system.collections.generic") $m = new-object '[system.collections.generic::hashset](string)' $m.gettype()
but running gives error. usage incorrect? have 2 lines of code!
unable find type [system.assembly]. make sure assembly contains type loaded. @ d:\untitled1.ps1:1 char:1 + [system.assembly]::loadwithpartialname("system.collections.generic") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : invalidoperation: (system.assembly:typename) [], runtimeexception + fullyqualifiederrorid : typenotfound new-object : cannot find type [[system.collections.generic::hashset] (string)]: verify assembly containing type loaded. @ d:\untitled1.ps1:2 char:6 + $m = new-object '[system.collections.generic::hashset](string)' + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : invalidtype: (:) [new-object], psargumentexception + fullyqualifiederrorid : typenotfound,microsoft.powershell.commands.newobjectcommand cannot call method on null-valued expression. @ d:\untitled1.ps1:3 char:1 + $m.gettype() + ~~~~~~~~~~~~ + categoryinfo : invalidoperation: (:) [], runtimeexception + fullyqualifiederrorid : invokemethodonnull
loadwithpartialname() in [system.reflection.assembly]
, not [system.assembly]
. also, new-object
syntax off.
[system.reflection.assembly]::loadwithpartialname("system.collections.generic") $m = new-object 'system.collections.generic.hashset[string]' $m.gettype()
see also: http://www.leeholmes.com/blog/2006/08/18/creating-generic-types-in-powershell/
Comments
Post a Comment