I have a Powershell script that is loading a .NET assembly (.EXE in my case) and calling a public method that uses the app.config to pull an encrypted connection string.
After researching further I found out the cause. At an earlier point in the script I was loading SMO:
$null = [reflection.assembly]::loadwithpartialname("microsoft.sqlserver.smo")
I believe this some how mangles my configuration settings. The fix was to do as Chris mentions above to this call first:
[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", $null)
$null = [reflection.assembly]::loadwithpartialname("microsoft.sqlserver.smo")
And then on my second call to another assembly do this:
$config_path = $assembly_exe + ".config"
[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", $config_path)
[Reflection.Assembly]::LoadFrom($assembly_exe)
Problem appears to be solved...
Try:
[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", $config_path)