使用Outlook地址簿时出现访问冲突异常

时间:2013-10-01 14:13:52

标签: c# wpf access-violation mapi outlook-2003

  

环境Win XP,Outlook 2003

  1. 我有一个WPF组件使用Interop.MAPI打开Outlook通讯录

  2. 用户将选择多个收件人并选择确定,然后关闭地址簿。

  3. 一旦弹出窗口关闭,我可以注意到等待光标到来,几秒钟后我收到错误消息,然后我的应用程序(WPF)被终止。

  4. 我花了好几个小时才发现它仍然没有运气,我从事件查看器中复制了以下异常。

    • 我发现地址簿模块没有问题 因为相同的地址簿用于其工作的不同模块中 细

    • 在我打开地址簿并阅读所选名称的方法中,从未达到过捕获块。

      

    异常信息:System.AccessViolationException       堆:          在MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG)   为ByRef)          在System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)          在System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)          在System.Windows.Window.ShowHelper(System.Object)          在System.Windows.Window.Show()          在System.Windows.Window.ShowDialog()          at xxxxx.Frw.Base.Client.UI.DialogService.ShowDialog(xxxxx.Frw.Base.Client.UI.BaseViewModel)          在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)          在MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(System.Windows.Input.ICommandSource,   布尔)          在System.Windows.Controls.Primitives.ButtonBase.OnClick()          在System.Windows.Controls.Button.OnClick()          在System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs)          在System.Windows.UIElement.OnMouseLeftButtonUpThunk(System.Object,   System.Windows.Input.MouseButtonEventArgs)          在System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate,   System.Object的)          在System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate,   System.Object的)          在System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object,   System.Windows.RoutedEventArgs)          在System.Windows.EventRoute.InvokeHandlersImpl(System.Object,System.Windows.RoutedEventArgs,Boolean)          在System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject,   System.Windows.RoutedEventArgs,System.Windows.RoutedEvent)          在System.Windows.UIElement.OnMouseUpThunk(System.Object,System.Windows.Input.MouseButtonEventArgs)          在System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate,   System.Object的)          在System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate,   System.Object的)          在System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object,   System.Windows.RoutedEventArgs)          在System.Windows.EventRoute.InvokeHandlersImpl(System.Object,System.Windows.RoutedEventArgs,Boolean)          在System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject,   System.Windows.RoutedEventArgs)          在System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs)          在System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs,   布尔)          在System.Windows.Input.InputManager.ProcessStagingArea()          在System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs)          在System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport)          在System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr,   System.Windows.Input.InputMode,Int32,   System.Windows.Input.RawMouseActions,Int32,Int32,Int32)          在System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr,   MS.Internal.Interop.WindowMessage,IntPtr,IntPtr,Boolean ByRef)          在System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr,Int32,IntPtr,IntPtr,Boolean ByRef)          在MS.Win32.HwndWrapper.WndProc(IntPtr,Int32,IntPtr,IntPtr,Boolean ByRef)          在MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)          在System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate,   System.Object,Int32)          在MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object,   System.Delegate,System.Object,Int32,System.Delegate)          在System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority,   System.TimeSpan,System.Delegate,System.Object,Int32)          在MS.Win32.HwndSubclass.SubclassWndProc(IntPtr,Int32,IntPtr,IntPtr)          在MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG)   为ByRef)          在System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)          在System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)          在System.Windows.Application.RunDispatcher(System.Object)          在System.Windows.Application.RunInternal(System.Windows.Window)          在System.Windows.Application.Run(System.Windows.Window)          在xxxxx.Frw.Main.Client.UI.App.Main()

1 个答案:

答案 0 :(得分:0)

即使我无法弄清楚导致此问题的原因,我找到了一个防止应用程序崩溃的解决方案,

由于未处理的异常将上次调用的托管代码方法显示为

  

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

在添加此属性后,我只是添加了一个带有HandleProcessCorruptedStateExceptions方法修饰的try catch,我能够捕获未受损害的MAPI互操作引发的异常并处理应用程序崩溃问题。

[HandleProcessCorruptedStateExceptions]
public void ShowDialog()
{
 try
  {
  }
 Catch(Exception ex)
  {
  }
}