I’m reading a password from a config file with my C# application (it’s a windows service). I’m using these lines:
private NameValueCollection appSettings = ConfigurationManager.AppSettings;
string password = appSettings["Password"];
The config looks like:
<add key="Password" value="exam&ple" />
The service can’t start because the application configuration is incorrect. If I remove the ‘&’, the service works. How could I control this problem?? Thanks.
You need to encode your values in the app.config like this