【问题标题】:How can I load an assembly and use it in powershell?如何加载程序集并在 powershell 中使用它?
【发布时间】:2013-09-12 12:08:15
【问题描述】:

我阅读了How to load assemblies in PowerShell? 上的建议,但我并没有真正理解它,也不知道如何将其应用于我的情况。

我正在尝试加载此程序集http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.binary.binaryformatter.aspx,以便我可以序列化一个对象,并且对 powershell 非常陌生,我觉得我的头晕了。

谁能指导我如何将这个程序集加载到脚本中?我收到错误:

make sure that the assembly containing this type is loaded

当我使用 Add-Type -Namespace System.Runtime.Serialization.Formatters.Binary 时,它会提示我输入我不知道如何提供的信息。

【问题讨论】:

    标签: powershell .net-assembly powershell-3.0


    【解决方案1】:

    BinaryFormatter 存在于mscorlib.dll 中并且已经加载。要创建新对象,您可以执行以下操作:

    $formatter = new-object System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
    

    【讨论】:

    • 附注:命名空间参数的用途与您猜测的不同。阅读Get-Help Add-Type -Parameter Namespace 了解更多信息。
    猜你喜欢
    • 2012-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-24
    • 2014-10-06
    • 1970-01-01
    • 2015-10-11
    • 1970-01-01
    相关资源
    最近更新 更多