Windows服务完全忽略配置文件

时间:2018-04-09 19:33:16

标签: c# visual-studio-2017 windows-services

问题在于,无论我放入配置文件(Service1.exe.config)甚至删除它 - Windows服务根本不关心,它仍然从某处提取数据。我也注意到当我在文件中搜索值(搜索字符串)时,我在服务的exe文件中找到了它!?这怎么可能?我该怎么做才能改变这种行为? 感谢

    SMARTService.Properties.Settings propRemote;
    SMARTService.LocalSettings propLocal;
    SMARTService.smtp propSmtp;

    protected override void OnStart(string[] args)
    {

            propRemote = SMARTService.Properties.Settings.Default;
            propLocal = SMARTService.LocalSettings.Default;
            propSmtp = SMARTService.smtp.Default;
    }

后来我在整个代码中使用它们。

设置文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <section name="SMARTService.smtp" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
            <section name="SMARTService.LocalSettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
            <section name="SMARTService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
        </sectionGroup>
    </configSections>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
    <applicationSettings>
        <SMARTService.smtp>
        ....
        </SMARTService.smtp>

        <SMARTService.LocalSettings>
        ....
        </SMARTService.LocalSettings>
        <SMARTService.Properties.Settings>
        ....
        </SMARTService.Properties.Settings>
    </applicationSettings>

</configuration>

0 个答案:

没有答案