none
Debugging tool for .NET application RRS feed

  • Question

  • My C# WinForm application consists of three EXEs and three DLLs.

    Each EXEs and DLLs write log when some error occurs.

    I need some debugging tool to find any problem in run-time.

    Is there any debugging tool in Visual Studio package or 3rd party?

    Sunday, March 29, 2020 3:39 AM

Answers

  • Are you using Visual Studio? If yes, did you try to hit F5 to run your application in debug mode and just add a few breakpoints where you may want to examine the code?

    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


    My TechNet articles

    • Marked as answer by Jeff0803 Monday, March 30, 2020 3:38 AM
    Sunday, March 29, 2020 3:47 AM
    Moderator
  • I need some debugging tool to find any problem in run-time.

    There is no debugging tool after the solution has been deployed that I know about. The best you can do is catch the runtime exception show it or log it.

    You can find any error at runtime by removing all try/catches in the Winform and classlib projects. By removing the try/catches, everything becomes unhandled exceptions where you can have global or centralized exception handler catch the exception,  log the error, or log it even if the exception is thrown in the DLL.

     https://www.codeproject.com/Articles/43182/Centralised-Exception-Handling-in-C-Windows-Applic

     I am using the concept in a 3 layer Winform Core 3.0 solution, and all exceptions from all 3 layers are  caught by the GEH in the Winfowm project the presentation layer.

    using System;
    using System.Windows.Forms;
    
    namespace PubCompanyWinCore
    {
        static class Program
        {
            /// <summary>
            ///  The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                // Add handler to handle the exception raised by main threads
                Application.ThreadException +=
                    new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
    
                // Add handler to handle the exception raised by additional threads
                AppDomain.CurrentDomain.UnhandledException +=
                    new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
    
                var startup = new Startup();
    
                // Stop the application and all the threads in suspended state.
                Environment.Exit(-1);
            }
    
            static void Application_ThreadException
                (object sender, System.Threading.ThreadExceptionEventArgs e)
            {
                // All exceptions thrown by the main thread are handled over this method
    
                ShowExceptionDetails(e.Exception);
            }
    
            static void CurrentDomain_UnhandledException
                (object sender, UnhandledExceptionEventArgs e)
            {
                // All exceptions thrown by additional threads are handled in this method
    
                ShowExceptionDetails(e.ExceptionObject as Exception);
            }
    
            static void ShowExceptionDetails(Exception Ex)
            {
                // Do logging of exception details
                MessageBox.Show(Ex.Message, Ex.TargetSite.ToString(),
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
    
                // Stop the application and all the threads in suspended state.
                Environment.Exit(-1);
            }
        }
    }
    
    


    • Edited by DA924x Sunday, March 29, 2020 7:43 AM
    • Proposed as answer by Naomi NModerator Sunday, March 29, 2020 2:07 PM
    • Marked as answer by Jeff0803 Monday, March 30, 2020 3:43 AM
    Sunday, March 29, 2020 7:01 AM
  • Hello,

    Usually there are telltale signs to where the exception is raised at runtime which leads to five ways to pinpoint where to look for a problem if this is on the development machines.

    • Application-wide unhandled exception handler (this gets things missed in bullets 3 and 4).
    • Using breakpoints (as Naomi recommended), see the following to learn the basics.
    • Use additional assertion where the error may occur e.g. rather than convert a string to a int, use TryParse.
    • Add try-catch statements with logging.
    • IntelliTrace (way cool), only available for Enterprise edition of Visual Studio. IntelliTrace collects (known as historical debugging) error information outside of Visual Studio and can allow a developer to replay a failed operation.

    If foreign is a new concept to you, go with breakpoints where each breakpoint may need adjustment to their location.

    Take time to read the following page and check out "set a breakpoint conditions.

    In regards to assertions, let's say you have code such as the following (full code here)

    while (await reader.ReadAsync(ct))
    {
    
        if (index % 50 == 0)
        {
            await Task.Delay(1);
        }
    
    
        progress.Report(index.ToString());
    
        personList.Add(new Person()
        {
            Id = await reader.GetFieldValueAsync<int>(0),
            FirstName = await reader.GetFieldValueAsync<string>(1),
            LastName = await reader.GetFieldValueAsync<string>(2),
            Street = await reader.GetFieldValueAsync<string>(3),
            City = await reader.GetFieldValueAsync<string>(4),
            State = await reader.GetFieldValueAsync<string>(5),
            PostalCode = await reader.GetFieldValueAsync<string>(6)
        });
    
        index += 1;
    
        if (ct.IsCancellationRequested)
        {
    
            if (personList.Count >0)
            {
                return personList;
            }
    
            ct.ThrowIfCancellationRequested();
        }
    
    }

    And the exception is thrown on the creating a person, the error might be in this case a null, index out of range or wrong type. Comment out all but one property assignment, run, no error, add another until the exception is thrown the fix usually using assertion prior to the assignment.

    In closing, use this problem as an opportunity, learn to use the techniques mentioned above. Review what Naomi and DA924x suggested to resolve the issue. If you get stuck once the error is located come back and ask for specific assistance.

    Hope this is helpful.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Proposed as answer by Naomi NModerator Sunday, March 29, 2020 2:07 PM
    • Marked as answer by Jeff0803 Monday, March 30, 2020 3:42 AM
    Sunday, March 29, 2020 10:27 AM
    Moderator

All replies

  • Are you using Visual Studio? If yes, did you try to hit F5 to run your application in debug mode and just add a few breakpoints where you may want to examine the code?

    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


    My TechNet articles

    • Marked as answer by Jeff0803 Monday, March 30, 2020 3:38 AM
    Sunday, March 29, 2020 3:47 AM
    Moderator
  • I need some debugging tool to find any problem in run-time.

    There is no debugging tool after the solution has been deployed that I know about. The best you can do is catch the runtime exception show it or log it.

    You can find any error at runtime by removing all try/catches in the Winform and classlib projects. By removing the try/catches, everything becomes unhandled exceptions where you can have global or centralized exception handler catch the exception,  log the error, or log it even if the exception is thrown in the DLL.

     https://www.codeproject.com/Articles/43182/Centralised-Exception-Handling-in-C-Windows-Applic

     I am using the concept in a 3 layer Winform Core 3.0 solution, and all exceptions from all 3 layers are  caught by the GEH in the Winfowm project the presentation layer.

    using System;
    using System.Windows.Forms;
    
    namespace PubCompanyWinCore
    {
        static class Program
        {
            /// <summary>
            ///  The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                // Add handler to handle the exception raised by main threads
                Application.ThreadException +=
                    new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
    
                // Add handler to handle the exception raised by additional threads
                AppDomain.CurrentDomain.UnhandledException +=
                    new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
    
                var startup = new Startup();
    
                // Stop the application and all the threads in suspended state.
                Environment.Exit(-1);
            }
    
            static void Application_ThreadException
                (object sender, System.Threading.ThreadExceptionEventArgs e)
            {
                // All exceptions thrown by the main thread are handled over this method
    
                ShowExceptionDetails(e.Exception);
            }
    
            static void CurrentDomain_UnhandledException
                (object sender, UnhandledExceptionEventArgs e)
            {
                // All exceptions thrown by additional threads are handled in this method
    
                ShowExceptionDetails(e.ExceptionObject as Exception);
            }
    
            static void ShowExceptionDetails(Exception Ex)
            {
                // Do logging of exception details
                MessageBox.Show(Ex.Message, Ex.TargetSite.ToString(),
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
    
                // Stop the application and all the threads in suspended state.
                Environment.Exit(-1);
            }
        }
    }
    
    


    • Edited by DA924x Sunday, March 29, 2020 7:43 AM
    • Proposed as answer by Naomi NModerator Sunday, March 29, 2020 2:07 PM
    • Marked as answer by Jeff0803 Monday, March 30, 2020 3:43 AM
    Sunday, March 29, 2020 7:01 AM
  • Hello,

    Usually there are telltale signs to where the exception is raised at runtime which leads to five ways to pinpoint where to look for a problem if this is on the development machines.

    • Application-wide unhandled exception handler (this gets things missed in bullets 3 and 4).
    • Using breakpoints (as Naomi recommended), see the following to learn the basics.
    • Use additional assertion where the error may occur e.g. rather than convert a string to a int, use TryParse.
    • Add try-catch statements with logging.
    • IntelliTrace (way cool), only available for Enterprise edition of Visual Studio. IntelliTrace collects (known as historical debugging) error information outside of Visual Studio and can allow a developer to replay a failed operation.

    If foreign is a new concept to you, go with breakpoints where each breakpoint may need adjustment to their location.

    Take time to read the following page and check out "set a breakpoint conditions.

    In regards to assertions, let's say you have code such as the following (full code here)

    while (await reader.ReadAsync(ct))
    {
    
        if (index % 50 == 0)
        {
            await Task.Delay(1);
        }
    
    
        progress.Report(index.ToString());
    
        personList.Add(new Person()
        {
            Id = await reader.GetFieldValueAsync<int>(0),
            FirstName = await reader.GetFieldValueAsync<string>(1),
            LastName = await reader.GetFieldValueAsync<string>(2),
            Street = await reader.GetFieldValueAsync<string>(3),
            City = await reader.GetFieldValueAsync<string>(4),
            State = await reader.GetFieldValueAsync<string>(5),
            PostalCode = await reader.GetFieldValueAsync<string>(6)
        });
    
        index += 1;
    
        if (ct.IsCancellationRequested)
        {
    
            if (personList.Count >0)
            {
                return personList;
            }
    
            ct.ThrowIfCancellationRequested();
        }
    
    }

    And the exception is thrown on the creating a person, the error might be in this case a null, index out of range or wrong type. Comment out all but one property assignment, run, no error, add another until the exception is thrown the fix usually using assertion prior to the assignment.

    In closing, use this problem as an opportunity, learn to use the techniques mentioned above. Review what Naomi and DA924x suggested to resolve the issue. If you get stuck once the error is located come back and ask for specific assistance.

    Hope this is helpful.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Proposed as answer by Naomi NModerator Sunday, March 29, 2020 2:07 PM
    • Marked as answer by Jeff0803 Monday, March 30, 2020 3:42 AM
    Sunday, March 29, 2020 10:27 AM
    Moderator
  • Yes I can debug from Visual Studio.

    However after I release my program to the customer, the program terminated accidentally without any error.(I can't install visual studio the the customer's PC)

    I left some log messages but the program terminates silently without error.

    I need some tool to monitor my program's working.

    Monday, March 30, 2020 3:42 AM
  • If you got the log file, this is the first thing I would start my troubleshooting from assuming the log file does have some info about the error.

    If not, that may be really tricky problem to figure out - you may need to connect to that customer to see the problem in action and hopefully you'll figure out this way what may be wrong.


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


    My TechNet articles

    Monday, March 30, 2020 4:06 AM
    Moderator
  • I left some log messages but the program terminates silently without error.

    That's why you should remove all try/catches everywhere and let the centralized exception handler catch all unhandled exceptions and log the exception message , the stack trace and the inner.exception message if it's not null. An exception was thrown, but it was unhandled by any try/catch so you think that no exception was thrown, but it was thrown that was never caught. 

    The centralized exception handler will catch it.

    Monday, March 30, 2020 5:17 AM
  • to debug crashes at runtime, we enable user mode dump files for our processes
    Collecting User-Mode Dumps
    then we have more infor for debugging than just the event log entries.

    the silent crash is since some versions ago: After upgrading to windows 10 1803 no WER window appears after any application going to crash
    Monday, March 30, 2020 8:52 AM
  • Probably worth a closer look (haven't used it for a while ...): DebugDiag

    https://channel9.msdn.com/Shows/Defrag-Tools/Defrag-Tools-121-DebugDiag-Part-1

    https://www.microsoft.com/en-us/download/details.aspx?id=58210


    With kind regards

    Monday, March 30, 2020 9:44 AM