我正在创建一个表单,其中我希望将一个值列表保存到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.作用域设置为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行)
特别是,似乎有问题的是
Return CType(Me("foodlist"), Global.System.Collections.Specialized.StringCollection)我做错了什么?
发布于 2022-02-28 02:28:44
我设法解决了这个问题后,通过从另一个论坛的建议。我转到我的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>我完全不知道为什么删除这个代码,因为我假设这是一个默认代码。
https://stackoverflow.com/questions/71263283
复制相似问题