繁体   English   中英

如何将程序集[Systems.Collections.Specialized.StringCollection]加载到Powershell中

[英]How to load assembly [Systems.Collections.Specialized.StringCollection] into Powershell

我半明白我的要求,并已尽我所能尽力对此进行研究。

我正在尝试使用[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文件吗?

要扩展来自@PetSerAl的评论,请执行以下操作:在System之后有一个s不应存在​​。 改为这样做

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM