2017-08-17 1 views
5

実行中のOutlookインスタンスと通信(または新しいインスタンスを開始)するC#Office VSTOアドインを開発しました。Office VSTOアドイン可能なアクセス許可の問題 - HRESULT 0x80004004(E_ABORT)

運転中止され(HRESULTからの例外:0x80004004(E_ABORT))

Outlookのタスクや予定を作成しようとしているときに

例外メッセージは以下の通りです...一部の顧客のPCにアクセス許可の問題を抱えて

Thここで起こっている:

Outlook.Account DefaultAccount = null; 
Outlook.Application outlookApp = GetOutlookApp(); //returns Application object of running Outlook instance/creates a new instance - it works for them. 

DefaultAccount = GetAccountForFolder(outlookApp); //returns the default account of the user. Tried it with a simple setup, only one account etc. - it works for them 
String defaultemailaddress; 

//CODE RUNS UNTIL THIS POINT 
if (DefaultAccount == null) //if somehow this would end up NULL, which is not the case, because: see code snippet below! 
{ 
    defaultemailaddress = outlookApp.Session.CurrentUser.AddressEntry.Address; 
} 
else 
{ 
    defaultemailaddress = DefaultAccount.SmtpAddress; //this could be the problem, but I can't debug it further, and it works in the code block below, to get the AccountType, so I don't understand why I couldn't get the SmtpAddress without a hard exception 
} 
//FAILS BEFORE THIS LINE COULD RUN. 
String email = "[email protected]"; 

ユーザーと接触して取得した後、彼らは本当に限られたアクセス許可セットとネットワークの下で実行していることを、私たちに語りました。

奇妙なことは、このコードのスニペットは、実際の接続がアドインOutlookおよびその他のOfficeの間で動作していることを、証明している、彼らのためにスムーズに実行されます。

Outlook.Application oApp = GetOutlookApp(); 
Outlook.Account DefaultAccount = GetAccountForFolder(oApp); 
String AccountType = DefaultAccount.AccountType.ToString(); 

IT部門がすでに調整してみました影響を受けるPC上のOutlookのセキュリティポリシー彼らはプログラムによるアクセスを許可しました。

管理者権限でツールを起動することはできませんが、必要はありません。アプリケーションが実際に正しく起動していることが証明されていますが、特定の機能しか実行できないように見えます...

私はまた、彼らはExchangeを使用していますが、明らかに同期に関する問題はありません(これらが何かに影響を与える場合は...)。これは私が見つけたコードスニペットであり、うまくいきました。

public static Outlook.Account GetAccountForFolder(Outlook.Application outlookApp) 
{ 
    // Obtain the store on which the folder resides. 
    Outlook.Store store = outlookApp.Session.DefaultStore; 

    // Enumerate the accounts defined for the session. 
    foreach (Outlook.Account account in outlookApp.Session.Accounts) 
    { 
     // Match the DefaultStore.StoreID of the account 
     // with the Store.StoreID for the currect folder. 
     if (account.DeliveryStore.StoreID == store.StoreID) 
     { 
      // Return the account whose default delivery store 
      // matches the store of the given folder. 
      return account; 
     } 
    } 
    // No account matches, so return null. 
    return null; 
} 
+0

GetAccountForFolderの実装について教えてください。 OutlookSpyで同じ問題を使用しますか? (名前空間ボタンをクリックし、アカウントを選択し、参照をクリックし、IEnumVariantタブに移動し、問題のアカウントをダブルクリックします)。 –

+0

こんにちはドミトリー!どのようなOutlook関連のあなたの積極的な作業をありがとう、私は多くのあなたのコメント/回答が役立っているのを発見した! OutlookSpyをインストールしてこの調査に使用するようユーザーに依頼する必要があるということですか? – Laureant

答えて

1

問題は、あなたがrace condition in a COM Add-In objectを持っていることである。このため、Interop.Outlookに表示されます。あなたはあなたの方法で人為的な遅延を起こすべきです。成功するまで再試行してください:

bool isDone = false; 
while (!isDone) 
{ 
    try 
    { 
     // your action with Add-In here... 

     isDone = true; 
    } 
    catch (System.Runtime.InteropServices.COMException exception) 
    { 
     // small delay 
     Thread.Sleep(10); 
    } 
} 
+0

私は参照してください。だから私はエラー0x80004004オブジェクトの1つが私のアドインでアクセスできないために取得します。ここで重要なのは、Outlookの外部からOutlookと通信しているということです。 – Laureant

0

アカウントを取得してから少し遅れてください。

Outlook.Account DefaultAccount = null; 
Outlook.Application outlookApp = GetOutlookApp(); 
DefaultAccount = GetAccountForFolder(outlookApp); 
Thread.Sleep(5000); // a bit of startup grace time. 

中止0x80004004エラーが頻繁に見Can only send email via Outlook if Outlook is open

関連する問題