I have been trying to find some answers on why service code, that I have built accessing Outlook using MAPI, works fine when it is being debugged within Visual Studio, but when the service is deployed, the call that gets the inbox, hangs. There is no timeout. The service just hangs.
Specifics:
1. Segment of code:
Application outlook = new Application();
NameSpace ns = outlook.GetNamespace("MAPI")
Folder folder = ns.GetDefaultFolder(olDefaultFolder.olFolderInbox) as Folder;
2. Outlook 2019 is installed on my PC.
3. Debugging code works fine. But, when I try to deploy this code a as a Windows Service, on my local machine, it will hang on the GetDefaulFolder. There is no return.
4. Project is a Window Service using the 4.7 .NET framework.
Has anyone else seen a similar issue? Thank you in advance for the help or suggestions.
What I have tried:
I have tried the following:
1. Adding impersonation around the code, even though the service is using my credentials.
2. FYI... I have added the STAThread attribute onto the parent method.
3. I have tried the code:
Application outlook = new Application();
Folder folder = outlook.Session.GetDefaultFolder(olDefaultFolder.olFolderInbox) as Folder;
4. Looked at properties on my local outlook. Nothing would cause this strange difference in behavior, even though it does seem to be some form of access or authentication where debugging resolves the issue.
5. Reviewed properties within the Administration screen - MAPI is enabled. But, then, it all works fine when I am debugging in Visual Studio, just not when deployed as a wondows service.
6. I have tried different threading models (i.e. Task.Factory, Timer,etc) , and each work fine when debugging within Visual Studio. I am currently using the standard BackGoundWorker class (i.e. BackgroundWorker bk = new BackgroundWorker(); bk.DoWork += MyServiceMethod(); bk.RunWorkerAsync();