Powershell Calling .NET Assembly that uses App.config

后端 未结 2 834
刺人心
刺人心 2020-12-02 16:04

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.

相关标签:
2条回答
  • 2020-12-02 16:30

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

    0 讨论(0)
  • 2020-12-02 16:51

    Try:

    [System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", $config_path)
    
    0 讨论(0)
提交回复
热议问题