PowerShell - loading dll’s and their dependent components

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of shuchi shuchi 10 months, 3 weeks ago.

  • Author
  • #32434
    Profile photo of shuchi

    Facing an issue in PowerShell while loading dll's and their dependent components.

    I have loaded a .NET (C#) dll's in PowerShell using Add-Type –Path as following, and this is working successfully.
    Add-Type -Path ($fileDirectory + "Contracts.dll")

    This dll has a function FindImage, which in turn loads few C dll's such as opencv_core300.dll, openCL.dll

    What are the possible ways to load these dependent(C) dll's.

  • #32438
    Profile photo of Dave Wyatt
    Dave Wyatt

    You don't really "load" unmanaged code into a .NET or PowerShell session, so far as I know. You just declare calls to them using .NET's interop functionality, and the .NET framework will access those DLLs as needed.

    If they're not actually installed on the path somewhere, then perhaps you need to make sure the .NET framework finds them in your "current" folder (which is different from what PowerShell will be showing you). Try doing this before calling your DLL's method, and see if it makes any difference:

    [Environment]::CurrentDirectory = $fileDirectory
  • #32480
    Profile photo of shuchi

    Hi Dave,
    Thanks for reply. Setting CurrentDirectory to $fileDirectory did not solved the issue. C/C++ dll's(dependent dll's) are not yet accessed by the .Net dll. If I place C/C++ dll's in the same folder as powershell.exe, then they are accessible. I don't want to disturb powershell.exe folder structure, so looking out for correct way so that these C/C++ dll's are picked up by .Net dll while script is executing.

  • #32619
    Profile photo of shuchi

    Thanks Dave for suggestion fix. It worked.
    Earlier error was due to some other cause

You must be logged in to reply to this topic.