I am trying to create a new Collections.Generic.Listtype object Amazon.Cloudwatch.Model.Dimensionsin Powershell 2.0.
I can create an object Amazon.Cloudwatch.Model.Dimensionssuccessfully using
> $dimension = New-Object Amazon.Cloudwatch.Model.Dimensions
And I can create an object of Collections.Generic.Listtype stringwith:
> $list = New-Object Collections.Generic.List[string]
However, when I try to create an object of Collections.Generic.Listtype Amazon.Cloudwatch.Model.Dimensions, I get the following error:
> $list = New-Object Collections.Generic.List[Amazon.Cloudwatch.Model.Dimension]
New-Object : Cannot find type
[Collections.Generic.List[Amazon.Cloudwatch.Model.Dimension]]: make sure the assembly containing this type is loaded.
At line:1 char:19
+ $list = New-Object <<<<
Collections.Generic.List[Amazon.Cloudwatch.Model.Dimension]
+ CategoryInfo : InvalidType: (:) [New-Object],
PSArgumentException
+ FullyQualifiedErrorId :
TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
The same statement works on Powershell 3.0, so it seems to be caused by how Powershell 2.0 generators look for assemblies. According to another SO answer , there is an error in Powershell 2.0:
However, there is a bad catch. PowerShell 2.0 has an error when mixing and matching BCL and third-party types as type parameters. The latter must have assembly qualifications:
# broken over two lines for clarity with backtick escape
$o = new-object ('collections.generic.dictionary[[{0}],[{1}]]' -f `
[type1].fullname, [type2].fullname)
, . PowerShell 3.0 .
() .
SO :
, . , :
$bar = new-object "System.Collections.Generic.Dictionary``2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"
:
> $list = New-Object "System.Collections.Generic.List``1[[Amazon.CloudWatch.Model.Dimension, AWSSDK.CloudWatch, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604]]"
.
> $list = New-Object "System.Collections.Generic.List``1[[Amazon.CloudWatch.Model.Dimension, AWSSDK.CloudWatch, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604]]"
New-Object : Cannot find type
[System.Collections.Generic.List`1[[Amazon.CloudWatch.Model.Dimension, AWSSDK.CloudWatch, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604]]]: make sure the assembly containing this type is loaded.
At line:1 char:22
+ $dimlist = New-Object <<<<
"System.Collections.Generic.List``1[[Amazon.CloudWatch.Model.Dimension, AWSSDK.CloudWatch, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604]]"
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
.
: Amazon.Cloudwatch.Model.Dimensions AWS SDK .NET