首页 > 解决方案 > VS Community 中的 VB 项目中的 app.config 错误

问题描述

我试图让我的应用程序读取我在 app.config 文件中为我的 VB 项目创建的变量,并且遇到两个错误。在 VS 社区中进行开发(最新并使用最新的 .Net 框架)。

  1. 当我单击触发代码以从 app.config 文件中读取变量的表单按钮时。我收到此错误:

链接到error1.jpg

该按钮触发此代码: Dim strKey As String strKey = My.Settings.TestKey

  1. 当我打开/关闭 app.config 文件时,我看到错误“读取 app.config 文件时发生错误。文件可能已损坏或包含无效的 XML”。我已经通过在线检查器运行了 XML,它通过了。我将在底部粘贴 app.config XML。

app.config 文件是自动生成的,TestKey 变量是通过项目属性页面添加到其中的,所以我根本没有手动修改 app.config 文件。

任何建议都非常感激。

干杯,

周杰伦

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System.Configuration.ConfigurationManager, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" >
            <section name="Doghunter.My.MySettings" type="System.Configuration.ClientSettingsSection, System.Configuration.ConfigurationManager, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" 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>
    <applicationSettings>
        <Doghunter.My.MySettings>
            <setting name="TestKey" serializeAs="String">
                <value>Zebedee</value>
            </setting>
        </Doghunter.My.MySettings>
    </applicationSettings>
</configuration>

标签: vb.netapp-config

解决方案


推荐阅读