exception when retriving user name

J

Jason Wang

I get exception while retrieving user name from email account profile in 2
computers, one is using pop3 account with OUtlook 2007, the other Exchange
account with Outlook 2003 (connected to Exchange server OK). No problems in a
few other PCs and XP/Vista VMs. Someone please tell me why and how to avoid
that.

Environment: VS2005, VSTO SE, Outlook 2003/2007, pop3/Exchange

The code (inside ThisAddIn_Startup method):

if (Application.Session.CurrentUser.Name == "Unknown")

The exception:

System.Runtime.InteropServices.COMException (0x9AC40201): The messaging
interface has returned an unknown error. If the problem persists, restart
Outlook.
at Microsoft.Office.Interop.Outlook.NameSpaceClass.get_CurrentUser()
at oAlert2003.ThisAddIn.ThisAddIn_Startup(Object sender, EventArgs e)
at Microsoft.Office.Tools.AddIn.OnStartup()
at oAlert2003.ThisAddIn.FinishInitialization()
at
Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecutePhase(String methodName)
at
Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecuteEntryPointsHelper()
 
D

Dmitry Streblechenko

It is possible that Outlook is not yet fully initialized when you process
the event.
Try to wait for the Application.MAPILogonComplete event.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top