Skip to main content
All docs
V24.2

Obtain an Exception's Call Stack in Visual Studio

  • 3 minutes to read

This article explains how to get an exception’s call stack in Visual Studio. This may be useful when you need to inform DevExpress Support about a problem that occurs at runtime and which you cannot reproduce step-by-step.

Get Exception Call Stack

Follow the steps below to catch user-handled exceptions in Visual Studio.

  1. Open Tools → Options… dialog, go to the Debugging node, and uncheck the Enable Just My Code (Managed Only) check box.
  2. Select the Debug → Windows → Exception Settings menu item (or press Ctrl+Alt+E). The Exceptions dialog appears. Enable the “Common Language Runtime Exceptions“ item.
  3. Reproduce the problem and open the Call Stack window (Debug | Windows | Call Stack).
  4. Select all text in the Call Stack window. Press Ctrl+C to copy the stack trace to the clipboard.
  5. Send the stack trace to DevExpress Support Center.

Refer to thew following article for more information: Manage exceptions with the debugger in Visual Studio.

Get Exception Call Stack in Multiple Threads

When an exception relates to cross-thread communications, it is necessary to analyze stack traces in all threads. To obtain this information, click the Debug → Windows → Threads menu item. In the Threads window, click the Expand callstacks item in the toolbar, select and copy all lines.

exception callstack expand callstacks

Get Exception Call Stack on an End-User Machine

If the exception occurs on your end user’s machine (or anytime when it is impossible to attach a debugger to the application to obtain the call stack), you can handle the FirstChanceException event and save the exception’s call stack programmatically.

The code sample below illustrates how to save the log file to an end user’s desktop.

// Place this code to the Main() method in your application.
AppDomain.CurrentDomain.FirstChanceException += (sender, e) => {
     System.Text.StringBuilder msg = new System.Text.StringBuilder();
     msg.AppendLine(e.Exception.GetType().FullName);
     msg.AppendLine(e.Exception.Message);
     System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace();
     msg.AppendLine(st.ToString());
     msg.AppendLine();
     String desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
     string logFilePath = String.Format("{0}\\{1}",desktopPath,"logfile.txt");
     System.IO.File.AppendAllText(logFilePath, msg.ToString());
 };

Get Exception Call Stack Of Design-Time Errors In Visual Studio

You can launch a new instance of Visual Studio and attach it to the first Visual Studio instance to collect an exception’s call stack.

  1. Open and launch the problematic project in the first Visual Studio.
  2. In the second Visual Studio, run the Debug → Attach to Processes command.
  3. In the invoked dialog, specify devenv.exe as a process to debug, and click the Attach button.
  4. Open Tools → Options… dialog, go to the Debugging node, and uncheck the Enable Just My Code (Managed Only) check box.
  5. Select the Debug → Windows → Exception Settings menu item (or press Ctrl+Alt+E). Enable Common Language Runtime Exceptions in the Exceptions dialog.
  6. Try to reproduce the problem in the first Visual Studio.
  7. Paste the stack trace information into your Issue Report in the DevExpress Support Center.
See Also