Sometimes I have an error, and the stack is 1/5th useful and 4/5th this: at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CheckForCircularReference (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonProperty property, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x00105] in <97722d3abc9f4cf69f9e21e6770081b3>:0
What the heck is [0x00105] in <97722d3abc9f4cf69f9e21e6770081b3>:0. It looks like it could be something referencing memory or a reference itself. My two questions are, why does it happen and is there a way to force compiler to give me actual helpful name and file?
Now I have to spend more time skimming past various layers, to find where the program ends and I have to backtrace every file and function, which I thought stacktraces were intended to help with. This doesn’t just apply to Newtonsoft, it happens to my C# source code as well.
The example issue on top has been resolved, I’m just interested why the hexadecimal representation of something that I can’t read. What happened to file/class name and line?
That looks like a memory address, and a hash type reference.
You already have all the info you need as it says “newtonsoft” and talks about Json. The other bits are for if you need to go deep and is useful, its essentially stack trace info.
It’s possible the Newtonsoft.Json distribution you are using (probably the asset store one?) doesn’t contain debug symbols. Also 97722d3abc9f4cf69f9e21e6770081b3 seems like a UUID to me.
Is this an error from the editor? Or from a built version of your game?
The problem you ACTUALLY have is circular references. Here is some sample code to demonstrate:
using UnityEngine;
public class CircularReferencesAndJSON : MonoBehaviour
{
[System.Serializable]
public class A
{
public B GetB;
}
[System.Serializable]
public class B
{
public A GetA;
}
private void Start()
{
var a = new A();
var b = new B();
a.GetB = b;
b.GetA = a;
var s = UnityEngine.JsonUtility.ToJson(a, prettyPrint:true);
Debug.Log("Unity tiny JSON:\n" + s);
// you'll need Newtonsoft JSON .NET from the Unity asset store:
var t = Newtonsoft.Json.JsonConvert.SerializeObject(a, Newtonsoft.Json.Formatting.Indented);
Debug.Log("Newtonsoft JSON .NET:\n" + t);
}
}
So the details of where inside of Newtonsoft it blows up is irrelevant. You have circular references preventing serialization.