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

Welcome Forums General PowerShell Q&A How to get Powershell to add types from an assembly it just loaded

Viewing 4 reply threads
  • Author
    Posts
    • #271054
      Participant
      Topics: 3
      Replies: 6
      Points: 18
      Rank: Member

      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

      (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:

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

      • This topic was modified 2 weeks, 4 days ago by kvprasoon. Reason: Code formatting
    • #271150
      Participant
      Topics: 16
      Replies: 1855
      Points: 3,568
      Helping Hand
      Rank: Community Hero

      After loading the assembly dll, you create a New-Object:

      Use Oracle ODP.NET and PowerShell to Simplify Data Access

    • #271249
      Participant
      Topics: 3
      Replies: 6
      Points: 18
      Rank: Member

      That looks promising and I’ll give it a shot although I wonder if you know the answer to my question why PoSH can’t find the assembly it just loaded?

    • #271387
      Participant
      Topics: 3
      Replies: 6
      Points: 18
      Rank: Member

      I used the code sample in the linked article and got further.  I was able to create the object but not open the connection.  Said TNS could not resolve the connect identifier, even though both ORACLE_HOME and TNS_ADMIN are correctly set and the tnsnames file has the correct entries (also used by other connection types (e.g. Microsoft Oracle connector in SSIS) that work OK)

      Any help would be great but I think this is an oracle question

    • #271402
      Participant
      Topics: 16
      Replies: 1855
      Points: 3,568
      Helping Hand
      Rank: Community Hero

      Oracle is a pain. Luckily, I have not had to deal with it in a couple years. The below discusses the TNSName.ORA and other items to successfully connect:

      https://purple.telstra.com/blog/using-powershell-to-query-oracle-dbs-without-using-the-oracle-client-oracle-data-provider-for-net

      As far as the assembly question, after the dll is loaded and the assemblies are available, you typically are creating a New-Object or referencing it with an accelerator (e.g. [myobject]::mymethod). I believe the -AssemblyName parameter is load a specific assembly from within a dll. This is not my strong suite, it’s not often that I’ve had to rely on loading a DLL to something in Powershell, especially as it’s become much more main stream with the community developing module wrappers to take the guesswork out of things like this.

Viewing 4 reply threads
  • You must be logged in to reply to this topic.