【问题标题】:Could not load file or assembly(dll file path+name) or one of its dependencies. An attempt was made to load a program with an incorrect format无法加载文件或程序集(dll 文件路径+名称)或其依赖项之一。试图加载格式不正确的程序
【发布时间】:2018-04-05 15:18:29
【问题描述】:

尝试执行时-

Import-Module 'C:\\Program Files\\Nimble Storage\\bin\\Nimble.Powershell.dll'

通过程序,我收到以下错误:

无法加载文件或程序集 'file:///C:\Program Files\Nimble Storage\bin\Nimble.Powershell.dll' 或其依赖项之一。一个 试图加载格式不正确的程序。

直接从 Powershell 运行时同样有效,但在上述情况下,面临问题。

使用过的C#程序和使用过的语句:

Collection< PSObject > resultCollection = runspaceInvoke.Invoke("Import-Module 'C:\\Program Files\\Nimble Storage\\bin\\Nimble.Powershell.dll'", null, out errors);

【问题讨论】:

  • 模块是 x86 并且您使用的是 x64 PowerShell 是我的猜测,反之亦然
  • 另外,“通过程序”是什么意思?什么节目?怎么样?
  • @EBGreen- 我的意思是 C# 程序。在那里,使用了语句: Collection resultCollection = runspaceInvoke.Invoke("Import-Module 'C:\\Program Files\\Nimble Storage\\bin\\Nimble.Powershell.dll'", null, out errors) ;
  • 请编辑您的问题以显示您正在使用的代码。

标签: powershell dll import-module


【解决方案1】:

EBGreen 是对的。需要看你的代码兄弟。如果没有,类似以下的东西应该可以工作:

using System.Management.Automation;
using System.Management.Automation.Runspaces;

class foo {
    static void Main(string[] args) {
        InitialSessionState initial = InitialSessionState.CreateDefault();
        initial.ImportPSModule(new string[] {"'C:\\Program Files\\Nimble Storage\\bin\\Nimble.Powershell.dll'"} );
        ...
    }
}

查看Creating an InitialSessionState了解更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-28
    • 2010-12-11
    • 2017-09-22
    • 2013-02-27
    • 2013-03-13
    • 2014-07-04
    • 1970-01-01
    相关资源
    最近更新 更多