开发者

Powershell dll loading

开发者 https://www.devze.com 2023-03-25 05:45 出处:网络
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\") | Out-Null

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") | Out-Null

Now, my C# library uses another library xyz.dll in it. I believe I don't need to load this in Powershell script, since the abc.dll will resolve it. However, I am getting an error saying:

Could not load file or assembly 'xyz, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file spe开发者_JAVA技巧cified.

Can someone please tell me how to fix this?


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)


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号