Possible problems with the Office VSTO add-in - HRESULT 0x80004004 (E_ABORT)

We developed a VSTO Office C # Office add-in that interacts with an executable instance of Outlook (or launches a new one), and it shows signs of resolving problems on some client computers when trying to create Outlook or destination tasks ...

Exception Message:

Operation canceled (exception from HRESULT: 0x80004004 (E_ABORT))

This is happening here:

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 = "test@emailserver.com";

After contacting the user, they told us that they work under a very limited set of permissions and a network.

It’s strange that this piece of code works fine for them, which proves that the connection works between Outlook and another Office add-in:

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

- Outlook . .

, . , 3 ( ), , , , ...

, Exchange, , , ( - ...)

EDIT: GetAccountForFolder, Outlook.Account . , , , .

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;
}
+4
2

, COM. . , , :

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);
    }
}
+1

.

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

Aborted 0x80004004 Interop.Outlook - , . Outlook, Outlook

0

Source: https://habr.com/ru/post/1683885/


All Articles