Debugging Exceptions

In release builds it can be difficult to narrow down exactly what’s causing an exception. Thanks to DiFFoZ post here for sharing a technique to find the line number, summarized here for posterity:

  1. Unity logs an IL offset in square brackets to the Player.log file. This is not included in the stack trace sent to the game for the Client.log file unfortunately. For example 0x003db in this log:

    at SDG.Unturned.ResourceSpawnpoint..ctor (System.Byte newType, System.UInt16 newID, System.Guid newGuid, UnityEngine.Vector3 newPoint, System.Boolean newGenerated, SDG.Unturned.NetId netId) [0x003db] in <08e91a6d9e1d4bd5bf2e982fa4148205>:0
  2. Open the related assembly (in this case Assembly-CSharp.dll) in a c# decompiler like DnSpy or ILSpy.

  3. In ILSpy use Search (Ctrl+Shift+F) to find the method from the stack trace.

  4. Change display mode to IL with C#.

  5. Find related line, IL_03db in the 0x003db example case.