powershell - Loading app.config into the AppDomain -


i can't app.config file load app domain.

i'm using

[system.appdomain]::currentdomain.setdata("app_config_file", $config_path) 

from powershell calling .net assembly uses app.config app.config file still not loaded.

i've tried resetting cache explained in using currentdomain.setdata("app_config_file") doesn't work in powershell ise .

here test script:

$configfile = "{actualphysicalpath}\app.config" gc $configfile  add-type -assemblyname system.configuration [configuration.configurationmanager].getfield("s_initstate", "nonpublic, static").setvalue($null, 0) [configuration.configurationmanager].getfield("s_configsystem", "nonpublic, static").setvalue($null, $null) ([configuration.configurationmanager].assembly.gettypes() | {$_.fullname -eq "system.configuration.clientconfigpaths"})[0].getfield("s_current", "nonpublic, static").setvalue($null, $null)  [configuration.configurationmanager]::connectionstrings[0].name [system.appdomain]::currentdomain.setdata("app_config_file", $null) [configuration.configurationmanager]::connectionstrings[0].name [system.appdomain]::currentdomain.setdata("app_config_file", $configfile) [configuration.configurationmanager]::connectionstrings[0].name 

i'm getting connection strings stored in machine.config, rather in app.config.

how can specific app.config file loaded in app domain?

try moving setdata statement before getfield statement.

with powershell 5.0 on windows 10, guidance provided the link reference seems work: i'm able retrieve both appsettings , connectionstrings.

add-type -assemblyname system.configuration  # set full path of app.config $configpath = "c:\full\path\to\app.config"  [system.appdomain]::currentdomain.setdata("app_config_file", $configpath) [configuration.configurationmanager].getfield("s_initstate", "nonpublic, static").setvalue($null, 0) [configuration.configurationmanager].getfield("s_configsystem", "nonpublic, static").setvalue($null, $null) ([configuration.configurationmanager].assembly.gettypes() | {$_.fullname -eq "system.configuration.clientconfigpaths"})[0].getfield("s_current", "nonpublic, static").setvalue($null, $null)  [system.configuration.configurationmanager]::appsettings [system.configuration.configurationmanager]::connectionstrings 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -