Question

Environment Win XP , Outlook 2003

  1. I have a WPF component which Open outlook address book using Interop.MAPI

  2. User will select multiple receipients and select ok, Which then closes the address book.

  3. Once pop up is closed i can notice wait cursor comes and in few seconds i get the error message and then my application(WPF) is terminated.

I have spent hours to figure it out still no luck, I have copied the following exception from Event viewer.

  • I figured it out there is no issue with the address book module because same address book is used in different module where it works fine.

  • Catch block never reached in that method where i open address book and read selected names.

Exception Info: System.AccessViolationException Stack: at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef) at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame) at System.Windows.Window.ShowHelper(System.Object) at System.Windows.Window.Show() at System.Windows.Window.ShowDialog() at xxxxx.Frw.Base.Client.UI.DialogService.ShowDialog(xxxxx.Frw.Base.Client.UI.BaseViewModel) at xxxxx.Frw.Base.Client.UI.DialogService.ShowDialog(xxxxx.Frw.Base.Client.UI.BaseViewModel, System.Windows.Controls.UserControl) at xxxxx.Frw.Region.Reu.Client.UI.ViewModels.ReportHeaderViewModel.ShowDistributionList() at xxxxx.Frw.Region.Reu.Client.UI.ViewModels.ReportHeaderViewModel.b__1(System.Object) at xxxxx.Frw.Base.Client.UI.Commands.RelayCommand.Execute(System.Object) at MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(System.Windows.Input.ICommandSource, Boolean) at System.Windows.Controls.Primitives.ButtonBase.OnClick() at System.Windows.Controls.Button.OnClick() at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs) at System.Windows.UIElement.OnMouseLeftButtonUpThunk(System.Object, System.Windows.Input.MouseButtonEventArgs) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate, System.Object) at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean) at System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject, System.Windows.RoutedEventArgs, System.Windows.RoutedEvent) at System.Windows.UIElement.OnMouseUpThunk(System.Object, System.Windows.Input.MouseButtonEventArgs) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate, System.Object) at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean) at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs) at System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs) at System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs, Boolean) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs) at System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport) at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr, System.Windows.Input.InputMode, Int32, System.Windows.Input.RawMouseActions, Int32, Int32, Int32) at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr, MS.Internal.Interop.WindowMessage, IntPtr, IntPtr, Boolean ByRef) at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) at System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr) at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef) at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame) at System.Windows.Application.RunDispatcher(System.Object) at System.Windows.Application.RunInternal(System.Windows.Window) at System.Windows.Application.Run(System.Windows.Window) at xxxxx.Frw.Main.Client.UI.App.Main()

Was it helpful?

Solution

Even though I couldnt figure out what was causing this issue I found a solution to prevent application crashing,

Since the unhandled exception shows the last invoked managed code method as

xxxxx.Frw.Base.Client.UI.DialogService.ShowDialog()

I simply added a try catch with HandleProcessCorruptedStateExceptions method decoration after adding this attribute I was able to catch exception thrown by unmaged MAPI interop and handle application crashing issue.

[HandleProcessCorruptedStateExceptions]
public void ShowDialog()
{
 try
  {
  }
 Catch(Exception ex)
  {
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top