Service 我在windows服务中遇到system.configuration.settingspropertynotfoundexception错误
我有一个windows应用程序,它使用SettingsProvider读取配置设置,并在文件不存在时设置默认值 工作正常,运转正常 我正在尝试编写启动此应用程序的windows服务。当它由服务运行时,我会在所有设置属性上获得Service 我在windows服务中遇到system.configuration.settingspropertynotfoundexception错误,service,windows-services,system.configuration,Service,Windows Services,System.configuration,我有一个windows应用程序,它使用SettingsProvider读取配置设置,并在文件不存在时设置默认值 工作正常,运转正常 我正在尝试编写启动此应用程序的windows服务。当它由服务运行时,我会在所有设置属性上获得System.Configuration.SettingsPropertyNotFoundException 当服务运行应用程序时,如何解决此异常?这意味着应用程序无法读取.Settings文件。我可以想到两个可能的原因: 该服务在没有访问.settings文件权限的帐户下运
System.Configuration.SettingsPropertyNotFoundException
当服务运行应用程序时,如何解决此异常?这意味着应用程序无法读取.Settings文件。我可以想到两个可能的原因:
然而,谷歌的一个结果发现了一个我没有想到的明显的可能原因。上次编译后是否添加了.settings?在Visual Studio中编译应用程序,然后重试…另一个可能的原因是您编写的自定义
设置Provider
在初始化期间引发异常
就我而言,我做到了:
public class CustomSettingsProvider : SettingsProvider
{
public override void Initialize(string name, NameValueCollection config)
{
base.Initialize(name, config);
}
}
由于name
始终作为null
传递,因此base.Initialize
引发了ArgumentNullException
。我通过传递一个非空名称修复了它,如下所示:
public override void Initialize(string name, NameValueCollection config)
{
base.Initialize(name ?? GetType().Name, config);
}