【问题标题】:How to load assembly [Systems.Collections.Specialized.StringCollection] into Powershell如何将程序集 [Systems.Collections.Specialized.StringCollection] 加载到 Powershell
【发布时间】:2015-10-01 16:34:05
【问题描述】:

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

我正在尝试使用 [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 Class 的文档,我想要的.dll 是System.dll。听起来它应该已经存在于我的系统上。

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

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

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

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

【问题讨论】:

  • System.Collections.Specialized.StringCollection
  • 啊。非常感谢你。很抱歉浪费时间。

标签: powershell .net-assembly stringcollection


【解决方案1】:

扩展来自@PetSerAl 的评论:System 之后的 s 不应该存在。改为这样做

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

【讨论】:

    猜你喜欢
    • 2012-10-07
    • 2018-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-19
    • 2014-10-06
    相关资源
    最近更新 更多