- This topic has 4 replies, 2 voices, and was last updated 2 weeks, 4 days ago by
November 12, 2020 at 10:15 am #271054
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 loadedPowerShell1[appdomain]::CurrentDomain.GetAssemblies() | Sort-Object -Property FullName | Select-Object -Property FullName
Oracle.ManagedDataAccess, Version=22.214.171.124, Culture=neutral, PublicKeyToken=89b483f429c47342
Next I want to load the classes defined in the assembly so I can use them, but this errors out:PowerShell1234567891011121314$oracletpe = Add-Type -AssemblyName 'Oracle.ManagedDataAccess' -PassThruAdd-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.AddTypeCommandAdd-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?
- This topic was modified 2 weeks, 4 days ago by kvprasoon. Reason: Code formatting
November 12, 2020 at 2:23 pm #271150ParticipantTopics: 16Replies: 1855Points: 3,568Rank: Community Hero
After loading the assembly dll, you create a New-Object:
November 12, 2020 at 11:35 pm #271249
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?
November 13, 2020 at 11:06 am #271387
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
November 13, 2020 at 12:06 pm #271402ParticipantTopics: 16Replies: 1855Points: 3,568Rank: 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:
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.
- You must be logged in to reply to this topic.