0

我半明白我在问什么,并尽我所能对此进行了研究。

我正在尝试使用 [Systems.Collections.Specialized.StringCollection] 类型的对象:

$newDBFiles = new-object Systems.Collections.Specialized.StringCollection;

我得到错误:

new-object : Cannot find type [Systems.Collections.Specialized.StringCollection]: make sure the assembly containing this type is loaded.
At line:1 char:15
+ $newDBFiles = new-object Systems.Collections.Specialized.StringCollection;
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

我尝试以几种不同的方式加载程序集但没有成功:

[System.Reflection.Assembly]::LoadWithPartialName("System.Collections.Specialized") | Out-Null;
    add-type -AssemblyName systems;
    add-type -AssemblyName systems.collections;

文档说这Add-Type将接受 .dll 的位置。查看StringCollection 类的文档,我想要的 .dll 是System.dll. 听起来它应该已经存在于我的系统上。

当我查看已经加载的程序集时,我看到了这个,在我看来这是正确的:

[appdomain]::currentdomain.getassemblies() | sort -property fullname | format-table fullname

System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a   

有很多关于使用该类型的帖子,但我找不到任何关于如何加载特定程序集的帖子。我需要一个特殊的 .dll 文件吗?

4

1 回答 1

2

扩展来自@PetSerAl 的评论:你后面不应该有一个s 。System改为这样做

$newDBFiles = new-object System.Collections.Specialized.StringCollection;
于 2015-10-01T17:01:02.643 回答