【问题标题】:Using two DLL files from PowerShell when one DLL file references the other one当一个 DLL 文件引用另一个 DLL 文件时,使用 PowerShell 中的两个 DLL 文件
【发布时间】:2012-01-04 01:00:21
【问题描述】:

我在 GAC 中有两个 DLL 文件。

DLL 文件 A 引用 DLL 文件 B。

我使用以下方法从 PowerShell 脚本加载 DLL 文件:

[Reflection.Assembly]::Load(full name of dll B)
[Reflection.Assembly]::Load(full name of dll A)

尽管如此,当 DLL 文件 A 需要使用 B 中的某个类时,我收到以下错误。

找不到文件'C:\WINDOWS\system32\WindowsPowerShell\v1.0\B.dll'。

【问题讨论】:

    标签: .net dll powershell .net-4.0 gac


    【解决方案1】:

    如果两个 dll 在同一个目录中,您可以尝试:

    [reflection.assembly]::loadfrom(full name of dll A)
    

    【讨论】:

    • 这解决了它。但这是一个意外:我们之前一直以管理员身份运行脚本,但我的大学曾经以普通用户身份运行它,然后它就可以工作了。到那时,Load 被 LoadFrom 取代。仍然困惑为什么在这种情况下用户拥有什么权限很重要......
    【解决方案2】:

    你可以使用:

    Add-Type -Path path\to\A.dll
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-01
      • 1970-01-01
      • 2012-02-16
      • 1970-01-01
      • 1970-01-01
      • 2012-05-17
      • 2022-01-05
      • 1970-01-01
      相关资源
      最近更新 更多