简体   繁体   中英

Error 'specified method is not supported'. Get call stack

My application is giving an error 'specified method is not supported' on a client pc. I do not know where the problem is coming from. He does not have Visual Studio installed so its impossible to debug.

Is there any way to get a call stack in WPF if I write some debug code in the application and give him the new exe?

You can subscribe to DispatcherUnhandledException to capture the unhandled exception at application level and to log stack trace of exception.

Example of DispatcherUnhandledException in App.xaml.cs

public App() {
        this.DispatcherUnhandledException += OnDispatcherUnhandledException;
    }

    void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) {
        string errorMessage = string.Format("An unhandled exception occurred: {0}", e.Exception.Message);
        MessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
        e.Handled = true;
    }

In a big picture you can capture a exception at : You can trap unhandled exceptions at different levels:

  1. AppDomain.UnhandledException From all threads in the AppDomain.
  2. Dispatcher.UnhandledException From a single specific UI dispatcher thread.
  3. Application.DispatcherUnhandledException From the main UI dispatcher thread in your WPF application.
  4. TaskScheduler.UnobservedTaskException from within each AppDomain that uses a task scheduler for asynchronous operations. You should consider what level you need to trap unhandled exceptions at.

Deciding between #2 and #3 depends upon whether you're using more than one WPF thread.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM