I have a windows app that uses SettingsProvider to read configuration settings and sets default values if file does not exist.
It works fine running normally.
I am trying to write a windows service that starts this app. When it is run by the service, I get System.Configuration.SettingsPropertyNotFoundException
on all the setting attributes.
How can I resolve this exception when the service is running the app?
This simply means that the app can't read the .Settings file. I can think of two possible causes:
The service runs under an account that doesn't have access to the .settings file. (or .config file, depending) This is unlikely because the service can start the app, and it wouldn't make sense for it to have permissions to the app and not the settings file.
The runtime can't find the settings file. It expects the settings to be in the root startup path of the executable. Check to ensure that it exists on the machine in question.
However, a google result turned up an obvious possible cause I haven't thought of. Were the .settings added after the last compile? Compile the app in Visual Studio, and try again...
Another possible cause is if you write a custom
SettingsProvider
that is throwing and exception duringInitialize
.In my case, I had done this:
Since
name
is always passed asnull
,base.Initialize
was throwing anArgumentNullException
. I fixed it by passing a non-null name like this: