Powershell Calling .NET Assembly that uses App.config

爱⌒轻易说出口 提交于 2019-11-27 11:42:51

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!