Trying to load .dll into PowerShell - Access Denied

This topic contains 1 reply, has 2 voices, and was last updated by  postanote 2 months, 3 weeks ago.

  • Author
    Posts
  • #94591

    squigee
    Participant

    Hi there,

    I'm trying to add an assembly into Powershell but I keep getting:

    Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly "path etc" or one of its dependencies. Access is denied."

    Does anyone know why I'm getting "Access Denied", I'm also running Powershell as admin and checked the .dll properties.

    # Load the assembly. I used a relative path so I could off using the Resolve-Path cmdlet 
    
    $ScriptDirectory = (gi $PSCommandPath).DirectoryName
    Join-Path $ScriptDirectory "taglib-sharp.dll"
    
    [Reflection.Assembly]::LoadFrom( (Resolve-Path "$ScriptDirectory"))
    
  • #94612

    postanote
    Participant

    Have you tried the below approach below instead?

        Add-Type -Path $Taglib-SharpDll
        $TagSharp = New-Object TagSharptype
    

    You call a static method like so:

        [TagSharptype.type]::method()
    

    Instead of Add-Type, you can also use reflection:

        [Reflection.Assembly]::LoadFile($Taglib-SharpDll)
    

    This approach is also calling the Reflection library and the LoadFile static method.

    See also:

    Load a Custom DLL from PowerShell

    One of the amazing features of PowerShell is its amazing reach. You can interact with the file system, the registry, certificate stores, COM, WMI, XML, cmdlets, providers … the list seems to go on forever.

    One important extension point is the ability to seamlessly interact with .NET DLLs. These are most commonly shipped in SDKs, and many people have made use of this.

    'leeholmes.com/blog/2006/10/27/load-a-custom-dll-from-powershell'

You must be logged in to reply to this topic.