自引用循环错误



我有一个自引用循环。我尝试阅读和实施其他一些答案,但它似乎不起作用。我有一个类将我的对象保存为 json 文件(方法(。它尝试序列化对象,但引发自引用循环的异常。我正在序列化的对象是第二个块(类(。如何解决此问题?在我添加按钮之前它确实有效,所以我假设我在处理程序上做错了什么,但我真的不知道。

  Public Sub saveLocalSettings()
        Console.WriteLine("saveLocalSettings")
        If Not Directory.Exists(_SettingsFile) Then
            Directory.CreateDirectory(_SettingsFile)
        End If
        '  Try
        Dim strConfigurationManager As String = JsonConvert.SerializeObject(_LocalSettings, PreserveReferencesHandling.Objects)
        'Dim strConfigurationManager As String = JsonConvert.SerializeObject(_LocalSettings, Newtonsoft.Json.ReferenceLoopHandling.Ignore)
        lm.writeFile(_SettingsFile + _FileName, strConfigurationManager, True)
        '  Catch ex As Exception
        ' End Try
    End Sub
Imports Newtonsoft.Json
Public Class RGOSetting
    Public Property id As String
    Public Property title As String
    Private mtbTitle As New MaskedTextBox
    Public Property sharestatus As Integer
    Public Property settingstring As String
    Public Property userid As Integer
    Public Property setting_profiles As New List(Of RGOSettingProfile)
    Private rgolcm As RGOLeagueChampionManager
    '  Private rgolssm As RGOLeagueSumSpManager
    Public btnUpdate As New Button
    Public btnReset As New Button
    Public btnClear As New Button
    End Class
Public Class RGOSettingProfile
    Public Property champion As LeagueChampion
    Public Property summoner_spells As New List(Of LeagueSummonerSpell)
    Public Sub New()
    End Sub
Public Sub New(ByVal strChampion As String, ByVal strSummonerSpell As List(Of String))
End Sub
End Class

我最终用按钮做了这件事,它允许我保存对象:

<JsonIgnore> Public btnUpdate As New Button
<JsonIgnore> Public btnReset As New Button
<JsonIgnore> Public btnClear As New Button

最新更新