I am working on some legacy code in .Net Framework 4.7.1 and trying to access app settings from MyActivity.dll.config. Said dll is being referenced and utilized by a Microsoft Workflow Foundations xaml file. When that code below is executed, it returns an empty string.
var string = ConfigurationManager.AppSettings["SMTPServer"]
I did some logging to a text file and verified it is coming back blank. I also checked for the presence of said config file being in the same directory as MyActivity.dll. Lastly, I checked and logged within the code the path of the assembly and it was in a weird place (C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\7d28ecb5\9e49f345\assembly\dl3\1e60f07b\5ff4cf31_9738d801\MyActivity.dll). For grins, I also placed a copy of the config file in there and nothing different happened. Below is a snippet of the config file.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="SMTPServer" value="smtp.office365.com"/>
</appSettings>
</configuration>
Anyone have any clue as to what may resolve this. Much thanks in advance!
CodePudding user response:
Please check the example i have created. My application name is ConsolApp2.
I have added configuration in the app.config file
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<appSettings>
<add key="SMTPServer" value="smtp.office365.com"/>
</appSettings>
</configuration>
After compile I got this in the ConsoleApp2.exe.config file
And for the getting this string you have to use using System.Configuration;
and with the code below you will get the configuration string
static void Main(string[] args)
{
string SMTPserver = ConfigurationManager.AppSettings["SMTPServer"];
}
Thanks
CodePudding user response:
I found the issue. This Workflow was being used by a 3rd party web app and the keys needed to belong in the web.config file. Hat tip to Paul Sinnema for pointing me in the right direction!