无法检索appsettings值

时间:2018-03-04 03:11:48

标签: .net vb.net visual-studio-2017 configurationmanager appsettings

检索appsettings我做错了什么?

app.config我有:

...
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup>
  <appSettings>
    <add key="culture" value="cs-CZ"/>
  </appSettings>
</configuration>

我正在尝试检索culture值:

Dim culture = ConfigurationManager.AppSettings("culture").ToString()

culture始终会产生Nothing

检索appsettings我做错了什么?

这是我的整个app.config文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <globalization uiculture="cs-CZ" culture="cs-CZ">
  </globalization>
  <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <section name="WindowsApplication1.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
        </sectionGroup>
    </configSections>

    <system.diagnostics>
        <sources>
            <!-- This section defines the logging configuration for My.Application.Log -->
            <source name="DefaultSource" switchName="DefaultSwitch">
                <listeners>
                    <add name="FileLog"/>
                    <!-- Uncomment the below section to write to the Application Event Log -->
                    <!--<add name="EventLog"/>-->
                </listeners>
            </source>
        </sources>
        <switches>
            <add name="DefaultSwitch" value="Information"/>
        </switches>
        <sharedListeners>
            <add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter"/>
            <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
            <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
        </sharedListeners>
    </system.diagnostics>
    <userSettings>
        <WindowsApplication1.My.MySettings>
            <setting name="txtPatientName" serializeAs="String">
                <value>Patient Name</value>
            </setting>
            <setting name="datastorage" serializeAs="String">
                <value/>
            </setting>
        </WindowsApplication1.My.MySettings>
    </userSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup>
  <appSettings>
    <add key="culture" value="cs-CZ"/>
  </appSettings>
</configuration>

0 个答案:

没有答案