Only on one server with windows server 2012 R2, I run the C# program just to read a value in app.config file under Administrator account. It returns null. But I run the program as a
Administrator, it works and returns correct value. What is the issue here? The code is:
and app.config is:
Administrator, it works and returns correct value. What is the issue here? The code is:
C#:
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
string firstFlag = "a";
try
{
//MessageBox.Show("读取前 First value="+firstFlag);
firstFlag = System.Configuration.ConfigurationManager.AppSettings["First"];
}
catch (Exception ex)
{
firstFlag = ex.ToString();
}
MessageBox.Show("First="+firstFlag);
Application.Run(new Form1());
}
XML:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="First" value="0" />
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
Last edited by a moderator: