Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么当我尝试序列化当前视图模型WPF应用程序以便以后保存状态时,它应该被取消消毒,因为我得到了StackOverflowException?_C#_Wpf_Serialization_Mvvm - Fatal编程技术网

C# 为什么当我尝试序列化当前视图模型WPF应用程序以便以后保存状态时,它应该被取消消毒,因为我得到了StackOverflowException?

C# 为什么当我尝试序列化当前视图模型WPF应用程序以便以后保存状态时,它应该被取消消毒,因为我得到了StackOverflowException?,c#,wpf,serialization,mvvm,C#,Wpf,Serialization,Mvvm,我尝试将“this”序列化为json我做了什么不正确? 我尝试序列化当前视图模型WPF应用程序以保存状态,例如,当我传递this.ProprtyName时,它可以工作,但我需要序列化视图模型中的所有数据,所以我可以做什么?您需要从类中显示更多内容,以了解发生了什么 这可能是因为您有一个父属性,该属性再次具有要序列化为属性的对象。这将导致一个无休止的循环=>StackOverflowException这是不够的上下文。它是如此大的模型,但谢谢。 private async void SynthCo

我尝试将“this”序列化为json我做了什么不正确?
我尝试序列化当前视图模型WPF应用程序以保存状态,例如,当我传递this.ProprtyName时,它可以工作,但我需要序列化视图模型中的所有数据,所以我可以做什么?

您需要从类中显示更多内容,以了解发生了什么


这可能是因为您有一个父属性,该属性再次具有要序列化为属性的对象。这将导致一个无休止的循环=>StackOverflowException

这是不够的上下文。它是如此大的模型,但谢谢。
private async void SynthCodeExecute(object param)
        {
            try
            {
                using (var fileStream = new FileStream(@"C:\Users\Desktop\report\Config123.cfg", FileMode.Create))
                using (var streamWriter = new StreamWriter(fileStream))
                using (var jsonWriter = new JsonTextWriter(streamWriter))
                {
                    JsonSerializer ser = new JsonSerializer();
                    ser.Formatting = Newtonsoft.Json.Formatting.Indented; //Format the output
                    ser.TypeNameHandling = TypeNameHandling.Auto;
                    ser.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                    ser.NullValueHandling = NullValueHandling.Ignore;
                    ser.Serialize(jsonWriter, this); //Serailizing View Model objects
                    jsonWriter.Flush();
                }

            }
            catch (Exception)
            {
                throw;
            }
        }