我有一个Powershell脚本,我想在其中创建在自定义(C++ / CLI)程序集中定义的类型的通用列表。
如果运行new-object My.Namespace.MyClass
,则可以整天创建对象。但是,如果运行new-genericobject System.Collections.Generic.List -Of My.Namespace.MyClass
,则会出现以下错误:
New-GenericObject : Could not construct Closed Type using the provided arguments.
At line:1 char:18
+ new-genericobject <<<< System.Collections.Generic.List -Of My.Namespace.MyClass
+ CategoryInfo : NotSpecified: (:) [New-GenericObject], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Pscx.Commands.NewGenericObjectCommand
我可以创建字符串列表,因此new-genericobject的基本功能很好。有没有人知道此错误的含义以及如何解决?
最佳答案
您可以尝试以下方法吗:
$list = new-object 'collections.generic.list[my.namespace.myclass]'
顺便说一句,您正在使用哪个版本的Powershell?什么操作系统?
更新
这可能是一个长期运行的错误,其中,如果元素类型在第三方程序集中,而集合不在同一程序集中,则必须完全限定该元素类型。试试这个:
$list = new-object ("collections.generic.list[[{0}]]" `
-f [MyClass].AssemblyQualifiedName)
关于powershell - 在Powershell中创建通用列表时出现“Could not construct Closed Type using the provided arguments”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8004438/