I'm trying to figure out what is causing a crash in our Outlook plugin. We're seeing this error:
System.Runtime.InteropServices.COMException (0x8E640201): An internal support function returned an error.
at Microsoft.Office.Interop.Outlook.AddressEntry.get_AddressEntryUserType()
at DropSendOutlook.RecipientAddressGetter.GetSmtpAddress(AddressEntry addressEntry)
at DropSendOutlook.RecipientAddressGetter.<Get>b__0(Recipient recipient)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.<DistinctIterator>d__64`1.MoveNext()
at System.String.Join(String separator, IEnumerable`1 values)
at DropSendOutlook.RecipientAddressGetter.Get(MailItem mail)
at DropSendOutlook.ThisAddIn.outlookApp_ItemSend(Object item, Boolean& cancel)
Based on this stack trace, it's clear the problem is in this function:
private static string GetSmtpAddress(AddressEntry addressEntry)
{
var addressEntryUserType = addressEntry.AddressEntryUserType;
Log.Info(addressEntryUserType);
//Now we have an AddressEntry representing the Sender
if (addressEntryUserType == OlAddressEntryUserType.olExchangeUserAddressEntry
|| addressEntryUserType == OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
{
//Use the ExchangeUser object PrimarySMTPAddress
ExchangeUser exchUser = addressEntry.GetExchangeUser();
return exchUser != null ? exchUser.PrimarySmtpAddress : GetSmtpAddressExchangeOld(addressEntry);
}
if (addressEntryUserType == OlAddressEntryUserType.olSmtpAddressEntry)
{
return addressEntry.Address;
}
if (addressEntryUserType == OlAddressEntryUserType.olOutlookContactAddressEntry)
{
// Could throw System.Runtime.InteropServices.COMException (0x8004010F), possible reasons with permissions.
try
{
try
{
var contact = addressEntry.GetContact();
if (contact != null && contact.Email1AddressType == "EX")
{
var currentDisplayName = contact.Email1DisplayName;
contact.Email1DisplayName = string.Empty;
var separators = new[] { '(', ')' };
var eMailParse = contact.Email1DisplayName.Split(separators);
contact.Email1DisplayName = currentDisplayName;
return eMailParse[1];
}
}
catch
{
var ms = new FrmMessage();
ms.SetMessage("Contact was not found!");
ms.Show();
throw;
}
}
catch (System.Exception ex)
{
Log.Error(ex.ToString());
}
return addressEntry.Address;
}
if (addressEntryUserType == OlAddressEntryUserType.olExchangeDistributionListAddressEntry)
{
var exchDistribution = addressEntry.GetExchangeDistributionList();
return exchDistribution != null
? exchDistribution.PrimarySmtpAddress
: GetSmtpAddressExchangeOld(addressEntry);
}
if (addressEntryUserType == OlAddressEntryUserType.olOutlookDistributionListAddressEntry)
{
var addresses = from AddressEntry member in addressEntry.Members select GetSmtpAddress(member);
return string.Join(";", addresses);
}
return addressEntry.Address;
}
And appears to be coming from this line specifically:
var addressEntryUserType = addressEntry.AddressEntryUserType;
What is causing this? Is there some kind of check we should be making before accessing AddressEntryUserType
to avoid this error?
User contributions licensed under CC BY-SA 3.0