servicewindows-servicessystem.configuration

I get a system.configuration.settingspropertynotfoundexception error in windows service


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?


Solution

  • This simply means that the app can't read the .Settings file. I can think of two possible causes:

    1. 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.

    2. 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...