【问题标题】:VB My.Settings Configuration Error ExceptionVB My.Settings 配置错误异常
【发布时间】:2022-07-16 05:11:47
【问题描述】:

我正在创建一个表单,我想在其中将值列表保存到 My.Settings。在表单中,将对列表进行更改,当我关闭表单时,更新的列表将保存到设置中。下次我启动表单时,我的列表将从 My.Settings 获取值。

这是我到目前为止所做的。 从设置中加载列表:

Dim fl As New List(Of String)
For Each Item As String In My.Settings.foodlist
            fl.Add(Item)
        Next

然后在关闭表单时将列表保存到设置中:

My.Settings.foodlist.Clear()
For Each Item As String In fl
   My.Settings.foodlist.Add(Item)
Next
My.Settings.Save()
Form1.Close()

在我的项目设置中,我将 foodlist 定义为 system.collection.specialized.stringcollection。范围设置为用户,当前值为空。

但是,当我运行时,我收到一条错误消息 System.Configuration.ConfigurationErrorsException: 'Configuration system failed to initialize' ConfigurationErrorsException:无法识别的配置部分 system.diagnostics。 (C:\Users\samsj\Downloads\EatWhat_webversion\WinFormsApp_22Feb\bin\Debug\net6.0-windows\EatWhat_webver.dll.config 第 5 行)

特别是,似乎有问题的行是

Return CType(Me("foodlist"), Global.System.Collections.Specialized.StringCollection)

我做错了什么?

【问题讨论】:

    标签: vb.net


    【解决方案1】:

    在查看了另一个论坛的建议后,我设法解决了这个问题。我去了我的 dll.config 文件并删除了整个 system.diagnostics 代码:

    <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>
    

    我完全不知道为什么删除此代码有效,因为我认为这是默认代码。

    【讨论】:

      【解决方案2】:

      这几天让我发疯。我升级到了 VS 2022,重新启动了 Windows,运行了我的防病毒软件,检查了我的注册表,除了跳雨舞之外什么都做了。当然,MS 必须知道这是一个严重的、普遍存在的问题。

      感谢您解决我的问题!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-09-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多