当我尝试序列化具有类似结构的对象时,我的C#程序正在运行StackOverflowException:
下面的示例代码:
class Chacha
{
public Chacha NextChacha { get; set; }
}
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All,
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};
static void Main(string[] args)
{
int count = 15000;
Chacha[] steps = new Chacha[count];
steps[0] = new Chacha();
for (int i = 1; i < count; i++)
{
steps[i] = new Chacha();
steps[i-1].NextChacha = steps[i];
}
string serSteps = JsonConvert.SerializeObject(steps, Settings);
}
Run Code Online (Sandbox Code Playgroud)
JSON.NET版本是:9.0.1
.NET Framework:4.5.2有什么 …