locked
How to get Powershell to add types from an assembly it just loaded RRS feed

  • General discussion

  • I loaded an assembly using Add-Type:

         $Typename = '\\crtwfaadvlkv0.d2dbfg.com\PRODUCTION\Vision\Apps\VisionPipeline\Oracle.ManagedDataAccess.dll'
         Add-Type -LiteralPath $TypeName

    and confirmed it was loaded

        > [appdomain]::CurrentDomain.GetAssemblies() |
        >> Sort-Object -Property FullName |
        >> Select-Object -Property FullName;

        (partial results)
        
        Oracle.ManagedDataAccess, Version=4.122.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342

    Next I want to load the classes defined in the assembly so I can use them, but this errors out:

        > $oracletpe = Add-Type -AssemblyName 'Oracle.ManagedDataAccess' -PassThru
        Add-Type : Cannot add type. The assembly 'Oracle.ManagedDataAccess' could not be found.
        At line:1 char:14
        + ... oracletpe = Add-Type -AssemblyName 'Oracle.ManagedDataAccess' -PassTh ...
        +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            + CategoryInfo          : ObjectNotFound: (Oracle.ManagedDataAccess:String) [Add-Type], Exception
            + FullyQualifiedErrorId : ASSEMBLY_NOT_FOUND,Microsoft.PowerShell.Commands.AddTypeCommand
        
        Add-Type : Cannot add type. One or more required assemblies are missing.
        At line:1 char:14
        + ... oracletpe = Add-Type -AssemblyName 'Oracle.ManagedDataAccess' -PassTh ...
        +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            + CategoryInfo          : InvalidData: (:) [Add-Type], InvalidOperationException
            + FullyQualifiedErrorId : ASSEMBLY_LOAD_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand

    So, it looks like PowerShell can't find the assembly it just loaded. What am I doing wrong?

    Thursday, November 12, 2020 6:18 PM