Powershell dll loading

前端 未结 3 1864
有刺的猬
有刺的猬 2020-12-17 18:15

I have a Powershell script that calls a method in a C# library. The library dll is loaded as:

[Reflection.Assembly]::LoadFrom(\"$automationHome\\dll\\abc.dll         


        
相关标签:
3条回答
  • 2020-12-17 18:45

    A couple of ideas:

    Does the reference to xyz.dll from abc.dll (add reference) have the specific version property set to true (default setting) and you are using a later version of xyz.dll?

    For some assemblies the only way to get them to work is o load them into the GAC. You may want to try loading xyz into the GAC.

    0 讨论(0)
  • 2020-12-17 19:00

    LoadFrom() should ideally look for the xyz.dll in the same directory as abc.dll

    If you are running the script from the same directory as the dlls, add the below and then do the LoadFrom()

    $currentScriptDirectory = Get-Location
    [System.IO.Directory]::SetCurrentDirectory($currentScriptDirectory.Path)
    
    0 讨论(0)
  • 2020-12-17 19:05

    Make sure the dependency dll xyz is in the path that LoadLibrary will use. I think in your case that will be anything local to the powershell script, anything in a sub directory of the power shell script, or anything in the path variable or in the GAC.

    0 讨论(0)
提交回复
热议问题