首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VB My.Settings配置错误异常

VB My.Settings配置错误异常
EN

Stack Overflow用户
提问于 2022-02-25 08:50:44
回答 1查看 145关注 0票数 0

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

到目前为止,这就是我所做的。若要从设置加载列表,请执行以下操作:

代码语言:javascript
复制
Dim fl As New List(Of String)
For Each Item As String In My.Settings.foodlist
            fl.Add(Item)
        Next

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

代码语言:javascript
复制
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.作用域设置为user,该值当前为空。

但是,当我运行时,我会收到一个错误,它说System.Configuration.ConfigurationErrorsException:‘配置系统无法初始化’ ConfigurationErrorsException:无法识别的配置节system.diagnostics‘。(C:\Users\samsj\Downloads\EatWhat_webversion\WinFormsApp_22Feb\bin\Debug\net6.0-windows\EatWhat_webver.dll.config第5行)

特别是,似乎有问题的是

代码语言:javascript
复制
Return CType(Me("foodlist"), Global.System.Collections.Specialized.StringCollection)

我做错了什么?

EN

回答 1

Stack Overflow用户

发布于 2022-02-28 02:28:44

我设法解决了这个问题后,通过从另一个论坛的建议。我转到我的dll.config文件并删除了整个system.diagnostics代码:

代码语言:javascript
复制
<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>

我完全不知道为什么删除这个代码,因为我假设这是一个默认代码。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71263283

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档