Better Stack Trace for C# Development

For a long time, I’ve been wondering why the C# stack traces are so unreadable. I prefer to use C# over LUA or JS, because of its Intellisens and statically typed variables, but the C# stack traces in FiveM makes it a lot harder to debug and find where my problems originated.

While researching for this problem I found out that a better stack trace has been implemented for at least LUA and in the cookbook post " Improving script stack traces" they also show a better C# and JS stack trace. but I have never managed to replicate or get the same result.

This is the code that generates the intentional runtime error above

namespace CSErrorTest.Client {
    public class ClientMain : BaseScript {
        public ClientMain() {
            object o = null;
            string s = o.ToString();
        }
    }
}

Cookbook post: https://cookbook.fivem.net/2019/07/15/improving-script-stack-traces/

EDIT: Just in case someone is wondering, yes I’m running the latest server build and Scripting API

2 Likes

We use Embedded for client and Portable for server on the Debugging information and it works for us.

Can you give a more in-depth explanation on how this approach is implemented?
Thanks.