Powershell Calling .NET Assembly that uses App.config Powershell Calling .NET Assembly that uses App.config powershell powershell

Powershell Calling .NET Assembly that uses App.config


Try:

[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", $config_path)


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...