I have just finished my first hello world resource to get my head around setting up a project in C# for use with FiveM. Strangely the only issue I have had is that when I include Debug.WriteLine(“whatever”); anywhere in my client side script it causes a crash at runtime in game.
The server side script happily writes to the console, but the client side will fail to instantiate if the Debug.WriteLine is in the constructor or fail to invoke the callback if the Debug.WriteLine is in a callback function.
Any ideas because other than that I ain’t doing too bad!
Thanks for the reply, I am using the CitizenFX.Core.dll from the FiveM install directory for the client side and the CitizenFX.Core.dll from the FiveMServer install directory for the server side. I just double checked this.
Just to see if this helps, can you change it to Debug.Write() instead of Debug.WriteLine()?
If that doesn’t work either, comment the line out and see if the error still occurs. If the error is gone, then please enable “embedded” logging, change it back to Debug.WriteLine(), uncomment the line and rebuild and restart the resource. Then show the error message in the console that appears here.
(To enable embedded logging, go to your project properties -> Build -> Advanced… -> Output - Debugging information: Embedded)
OK so I swapped both my client and server builds to include embedded logging. I also swapped the Debug.WriteLine to Debug.Write.
Interestingly Debug.Write works absolutely fine - no errors whatsoever. So I swapped it back and ran it again, the error occurred again at the same point.
I have another screenshot. If I’m quite honest the output looks the same, so I’m not entirely sure I set up the debug correctly.
That’s indeed something that will cause more than just this issue. Always make sure you’re using 4.5.2. And regarding the Debug.WriteLine, if your data/string you print with that contains {} / [] then it will break. So for that, just use Debug.Write() and add a “\n” manually to the end. (It’s a know bug, just not fixed yet)