I want to test if My application crash dump can be debugged, so I need generate a crash dump of my application firstly, but I write it with C#, so anybody know how to trigger a crash.(In fact I test with many exceptions, unsafe code......, but don't get it). thanks ---- sorry, sorry,I just lost somethings: I build the application with unity3d, which will handle exceptions for me automatic, and generate a crash dump for me if application crash
thanks all for your answers, I just test all your methods in common c# application and all works, but not unity3d application written with C#, it seems unity3d do more, I think I need to email unity3d to get a answer. I will post here if I get it.
StackOverflowException
is a badass:Usage:
None of the answers crashed my app the way I was looking for. So here is the approach that worked for me.
It's easy enough to reproduce if you try to transform a null game object. For example, like this:
Well. The only good 100% way actualy crash CLR is to inject a native exception into the managed world.
Calling the Kernel32.dll's RaiseException() directly will immediately crash ANY C# application, and Unity Editor as well.
Happy crashing. Please note that in order to debug native and managed, you will need two instances of Visual Studio running. If you are developing native P/INVOKE plugin, set up it that Visual Studio Instance 1 is native debugger and uses Unity or your C# program as a Host program, and you attach to the Host program from another Visual Studio Instance.
For C# in Unity3D
There is
UnityEngine.Diagnostics.Utils.ForceCrash
(in Unity 2018.3)This can be used with one of the following
ForcedCrashCategory
enum parameter:For older versions of Unity:
UnityEngine.Application.ForceCrash(int mode)
For even older versions (Unity 5):
UnityEngine.Application.CommitSuicide(int mode)
From my experience, mode 0 causes a "unity handled" crash (where the Unity crash dialog appears), and mode 2 causes a "hard" crash where the Windows error dialog appears.
This seems consistent with this post by Smilediver on
mode
:(These methods are not documented as they were intended for Unity's internal use. They may also be marked
[Obsolete]
depending on your Unity version.)