Jan Hommes
Jan Hommes

Reputation: 5152

ConfigurationSettings.AppSettings returns null when called in autostart

I have the following line of code:

MsgBox(ConfigurationManager.AppSettings.Get("Path"))

and inside the app.config file this xml:

<appSettings>
    <add key="PATH" value="myPath"/>
</appSettings>

I then deploy the solution and save it (the exe and the xml-config file) to the appdata-roaming path:

C:\Users\<username>\AppData\Roaming\<solutionname>

when I run it by double click, the massage-box shows the value "myPath". When I set it to run in autostart and restart my machine, the massege-box is empty (null). Why the config-xml file can't be read on autostart?

Upvotes: 0

Views: 837

Answers (1)

Abdusalam Ben Haj
Abdusalam Ben Haj

Reputation: 5433

Consider having a look at this documentation ConfigurationManager.OpenExeConfiguration

It says :

Client applications use a global configuration that applies to all users, separate configurations that apply to individual users, and configurations that apply to roaming users. The userLevel value determines the location of the configuration file being opened. It indicates whether it has no user level (the configuration file is in the same directory as the application) or has a per-user level (the configuration file is in an application settings path determined by the user level type.).

I'm not sure if this is relevant (since you said it works when you double click) . But no harm if you try.

Upvotes: 1

Related Questions