2017-02-21 9 views
0

私は自分自身でこれを把握することができませんでしたので、私はあなたにそれを打つことを考えました。Outlookのアドレス帳にアクセスしようとすると、Windows 10でWPFフォームがクラッシュする

プログラム自体は、従業員のリストをOutlookアドレス帳のPDLと比較しています。問題は、私のWPFフォームがWindows 7上で完璧に動作することですが、Outlookのアドレス帳にアクセスしようとするとWindows 10でプログラムがクラッシュし、それ以外のものはすべて正常に機能します。

これは、Outlookにアクセスするためのコードです:

public class Outlookhelper 
    { 

    public List<String> GetDistributionListMembers() 
    { 
     List <String> returnlist = new List <String>(); 
     Outlook.Application application = new Outlook.Application(); 
     Outlook.SelectNamesDialog snd = 
      application.Session.GetSelectNamesDialog(); 
     Outlook.AddressLists addrLists = 
      application.Session.AddressLists; 
     foreach (Outlook.AddressList addrList in addrLists) 
     { 
      if (addrList.Name == "Global Adress List") 
      { 
       snd.InitialAddressList = addrList; 
       break; 
      } 
     } 
     snd.NumberOfRecipientSelectors = 
      Outlook.OlRecipientSelectors.olShowTo; 
     snd.ToLabel = "D/L"; 
     snd.ShowOnlyInitialAddressList = true; 
     snd.AllowMultipleSelection = false; 
     snd.Display(); 
     if (snd.Recipients.Count > 0) 
     { 
      Outlook.AddressEntry addrEntry = 
       snd.Recipients[1].AddressEntry; 
      if (addrEntry.AddressEntryUserType == 
       Outlook.OlAddressEntryUserType. 
       olExchangeDistributionListAddressEntry) 
      { 
       Outlook.ExchangeDistributionList exchDL = 
        addrEntry.GetExchangeDistributionList(); 
       Outlook.AddressEntries addrEntries = 
        exchDL.GetExchangeDistributionListMembers(); 
       if (addrEntries != null) 
        foreach (Outlook.AddressEntry exchDLMember 
         in addrEntries) 
        { 
         //System.Windows.Forms.MessageBox.Show(exchDLMember.Name); 
         returnlist.Add(exchDLMember.Name); 
        } 
      } 
     } 
    return returnlist; 
    } 
} 

そして、これは私がWindowsの10マシンのイベントビューアから取得するエラーメッセージです:

Application: PDL Updater.exe 
Framework Version: v4.0.30319 
Description: The process was terminated due to an unhandled exception. 
Exception Info: System.Runtime.InteropServices.COMException 
    at 



System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(System.RuntimeType) 
    at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(System.RuntimeType) 
    at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(System.RuntimeType, System.Object[], Boolean) 
    at System.RuntimeTypeHandle.CreateInstance(System.RuntimeType, Boolean, Boolean, Boolean ByRef, System.RuntimeMethodHandleInternal ByRef, Boolean ByRef) 
    at System.RuntimeType.CreateInstanceSlow(Boolean, Boolean, Boolean, System.Threading.StackCrawlMark ByRef) 
    at System.Activator.CreateInstance(System.Type, Boolean) 
    at System.Activator.CreateInstance(System.Type) 
    at PDLUpdater.Outlookhelper.GetDistributionListMembers() 
    at PDLUpdater.MainWindow.getPDLnames_Click(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.Controls.Primitives.ButtonBase.OnClick() 
    at System.Windows.Controls.Button.OnClick() 
    at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs) 
    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.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.Input.InputManager.ProcessStagingArea() 
    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 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) 
    at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(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.Application.RunDispatcher(System.Object) 
    at System.Windows.Application.RunInternal(System.Windows.Window) 
    at Contacts.App.Main() 

そして

Faulting application name: PDL Updater.exe, version: 1.2.9.0, time stamp: 0x58aae81e 
Faulting module name: KERNELBASE.dll, version: 10.0.10586.589, time stamp: 0x57cf948c 
Exception code: 0xe0434352 
Fault offset: 0x0000000000071f28 
Faulting process id: 0x2948 
Faulting application start time: 0x01d28b7a4e508b20 
Faulting application path: C:\Program Files\PDL Updater\PDL Updater.exe 
Faulting module path: C:\WINDOWS\system32\KERNELBASE.dll 
Report Id: dd5f897a-24c9-4dd0-979e-4f0cbd747a94 
Faulting package full name: 
Faulting package-relative application ID: 

*編集 これは例外です。それが私をスローするメッセージです。それが助けてくれるといいでしょう: Error Message

他に必要なものがあれば、私はそれを提供してくれるでしょう。これをやり遂げることを楽しみにしていますので、事前にお寄せいただきありがとうございます!

+0

デバッグ時に実行すると、どのラインが消えますか? – BugFinder

+0

クリックイベントハンドラで例外処理を追加し、メッセージ、コールスタックなどを含む例外全体を記録します。これは 'Exception.ToString()'で簡単に行うことができます。あなたは外部アプリケーションを呼び出そうとしています - 常に問題の可能性があります。アプリケーションが見つからない、間違った相互運用バージョン、何でも –

答えて

0

お使いのプラットフォームをターゲットにしよう:[ビルド]タブ→プラットフォームターゲットでVisual Studioで

→プロジェクトのプロパティ→= X86/X64 /どれCPU

変更プラットフォームターゲットとあなたをテスト応用。

0

コードをセカンダリスレッドで実行していますか?

Officeアプリケーションでは、シングルスレッドアパートメントモデルを使用しています。メインスレッドのみでOOMを使用する必要があります。マルチスレッドを使用する場合は、低レベルAPI(拡張MAPI)の使用を検討する必要があります。または、そのAPIの周りの任意のラッパー(たとえば、Redemptionなど)。

+0

これについて詳しく説明できますか?私は最近C#で始まり、誰かが書いたコードを引き継がなければならなかった。 これはWindows 10でのみ発生する問題ですか?両方のシステムで一貫したエラーが発生しないと私は困惑します。このプログラムのコードは、Windows 10でうまく動作する別々の2つのプログラムから取得されました。唯一の違いは、それがWindowsフォームアプリケーションであった前です。 – Lennart

+0

メインスレッドでコードを実行していますか? –

+0

メインスレッドで実行されています。 – Lennart

0

Outlook.Applicationオブジェクトのインスタンスを作成しようとすると、それは爆発するようです。

Outlookとアプリケーションが同じセキュリティコンテキストで実行されていることを確認してください。どちらのアプリも昇格された権限(Run As Administrator)で実行されていますか?

+0

ビジュアルスタディは、アプリケーションを起動しようとするたびに常に管理者権限を求めます。作成したセットアップファイルは、管理者権限でも実行されます。 私は2つのセクションにコードを分割して、Outlookが実行されているかどうかを確認します。 Outlookが実行されていない場合、アプリケーションは正常に動作します。 outlookが実行されている場合のコードに変更するだけです 'oApp = Outlook.ApplicationとしてMarshal.GetActiveObject(" Outlook.Application ");アプリケーションが失敗する行である 正確には – Lennart

+0

です。 。設定権は違いはありません - セキュリティコンテキストが重要です - あなたのコードが実行されているときに*両方の*アプリケーションで同じでなければなりません。 –

+0

しかし、どうすればそれを達成できますか?私はプログラムファイルにインストールし、.net Frameworkがインストールされているかどうかを確認するために管理者権限を必要とするInno Setupを使ってsetup.exeを作成しています(もしそうでなければインストールします)。 'PrivilegesRequired = lowest'でInno設定を実行すると、アプリケーションは意図したとおりに動作しますが、.netを確認することはできず、Program Filesにはインストールできません。 これについての解決策はありますか?それが可能であれば、インストール後にInno Setupの特権を変更する方法がありますか? – Lennart

関連する問題