问题描述
我有一个Windows应用程序,该应用程序使用SettingsProvider读取配置设置,并在文件不存在的情况下设置默认值.
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.
我正在尝试编写启动该应用程序的Windows服务.当它由服务运行时,我在所有设置属性上都得到System.Configuration.SettingsPropertyNotFoundException
.
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?
推荐答案
这仅表示该应用无法读取.Settings文件.我可以想到两个可能的原因:
This simply means that the app can't read the .Settings file. I can think of two possible causes:
-
该服务在无法访问.settings文件的帐户下运行. (或.config文件,视情况而定),这不太可能,因为该服务可以启动应用程序,并且对应用程序而不是设置文件具有权限是没有意义的.
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.
但是,谷歌搜索结果显示出一个我可能没有想到的明显原因.上次编译后是否添加了.settings?在Visual Studio中编译该应用,然后重试...
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...
这篇关于我在Windows服务中收到一个system.configuration.settingspropertynotfoundexception错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!