Aug 10, 2023

Error Powershell "Attempt to load Oracle client libraries threw BadImageFormatException"


If you have this issue at connect to oracle database from powershell using [Reflection.Assembly]::LoadWithPartialName("System.Data.OracleClient"), error:

"Attempt to load Oracle client libraries threw BadImageFormatException.  This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed."

That is because you have oracle client library 32 bits version on windows SO 64 bits version.

The Solution for this is use the powershell 32 bits version. So you must to replace from your command line:

powershell -executionpolicy bypass -file script_powershell.ps1


to this:

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe  -executionpolicy bypass -file script_powershell.ps1


That's all, i hope this will help.

NOTE: pls don't forget use try/catch commands in your powershell script for view issues or errors like this case, example:

    catch{
        echo "ERROR"
        Write-Host $_
        Write-Host $_.ScriptStackTrace
    }

No comments:

Post a Comment