CedarRapids
asked on
Changes to XXX.exe.config file are not retrieved on restart.
I have a Windows Service and I need it to reload its config file data when it is restarted so as to pick up any manual editing that may have occurred since the last build.
I reproduced the problem on a test Windows Form app.
Visual Studio 2015, .NET Framework 4.5.2, C#
“Name” and “Value” entries are made in VS 2015 Properties / Settings editing grid.
I can retrieve them using:
foreach (SettingsProperty currentProperty in Properties.Settings.Defaul t.Properti es)
{
string name = currentProperty.Name.ToStr ing(); // This shows all the "Name" fields in the config that existed after build time.
string value = currentProperty.DefaultVal ue.ToStrin g(); // This shows all the "Value" fields in the config that existed after build time.
}
But when changes are made to the X.exe.config file via text editor the above code will continue to display the same original values.
I can retrieve the new “Values” via the following code:
string newValue = Properties.Settings.Defaul t[currentP roperty.Na me].ToStri ng();
… However, I don’t know how to get any new or modified “Name” fields with which to use to retrieve the values.
The store has the “Values” does it not also contain the “Name” keys?
Can I force a reread of the X.exe.config file at restart?
If it is caching, can I stop it?
Please help,
Thanks,
Jim – long-time member, seldom-user
I reproduced the problem on a test Windows Form app.
Visual Studio 2015, .NET Framework 4.5.2, C#
“Name” and “Value” entries are made in VS 2015 Properties / Settings editing grid.
I can retrieve them using:
foreach (SettingsProperty currentProperty in Properties.Settings.Defaul
{
string name = currentProperty.Name.ToStr
string value = currentProperty.DefaultVal
}
But when changes are made to the X.exe.config file via text editor the above code will continue to display the same original values.
I can retrieve the new “Values” via the following code:
string newValue = Properties.Settings.Defaul
… However, I don’t know how to get any new or modified “Name” fields with which to use to retrieve the values.
The store has the “Values” does it not also contain the “Name” keys?
Can I force a reread of the X.exe.config file at restart?
If it is caching, can I stop it?
Please help,
Thanks,
Jim – long-time member, seldom-user
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the prompt responses.
Re: Comment by Shaun
A load at OnStart does not force a full load to the point where the Keys and Value can be retrieved by
foreach (SettingsProperty currentProperty in Properties.Settings.Defaul t.Properti es)
The only way to retrieve new or changed “Names” is after rebuilding. A reboot does not even change them.
That is the whole point of my post.
Re: Comment by Snarf0001
What I have inherited is a Windows Service which stores its email Accounts and Passwords as the Name – Values. With type as Connection string), it makes it really easy to magically encrypt/decrypted. They wish to add accounts or change passwords with just a restart of the service. You say Properties.Settings isn’t intended for that. OK,
I believe you. It just seems odd I can access new dynamic “Values” but not a list of Keys.
A Windows Service does not have a Web.config. Are suggesting using the
So I made a hybrid X.exe.config with
<applicationSettings>
<connectionStrings>
<appSettings>
I can read the first set via Properties.Settings
I can then read the latter two sets via System.Configuration.Confi gurationMa nager.AppS ettings & System.Configuration.Confi gurationMa nager.Conn ectionStri ngs
Snarf0001? Are you really expecting 999 more Snarfs?
Thank for the help,
Jim
Re: Comment by Shaun
A load at OnStart does not force a full load to the point where the Keys and Value can be retrieved by
foreach (SettingsProperty currentProperty in Properties.Settings.Defaul
The only way to retrieve new or changed “Names” is after rebuilding. A reboot does not even change them.
That is the whole point of my post.
Re: Comment by Snarf0001
What I have inherited is a Windows Service which stores its email Accounts and Passwords as the Name – Values. With type as Connection string), it makes it really easy to magically encrypt/decrypted. They wish to add accounts or change passwords with just a restart of the service. You say Properties.Settings isn’t intended for that. OK,
I believe you. It just seems odd I can access new dynamic “Values” but not a list of Keys.
A Windows Service does not have a Web.config. Are suggesting using the
So I made a hybrid X.exe.config with
<applicationSettings>
<connectionStrings>
<appSettings>
I can read the first set via Properties.Settings
I can then read the latter two sets via System.Configuration.Confi
Snarf0001? Are you really expecting 999 more Snarfs?
Thank for the help,
Jim
Open in new window