How can I debug an internal error in the .NET Runtime?

后端 未结 5 421
滥情空心
滥情空心 2021-01-30 01:05

I am trying to debug some work that processes large files. The code itself works, but there are sporadic errors reported from the .NET Runtime itself. For context, the

5条回答
  •  暖寄归人
    2021-01-30 01:17

    Try writing a generic exception handler and see if there is an unhandled exception killing your app.

        AppDomain currentDomain = AppDomain.CurrentDomain;
        currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyExceptionHandler);
    
    static void MyExceptionHandler(object sender, UnhandledExceptionEventArgs e) {
            Console.WriteLine(e.ExceptionObject.ToString());
            Console.WriteLine("Press Enter to continue");
            Console.ReadLine();
            Environment.Exit(1);
    

提交回复
热议问题