AddinModule.CurrentInstance.OutlookApp.Session something here is null

Add-in Express™ Support Service
That's what is more important than anything else

AddinModule.CurrentInstance.OutlookApp.Session something here is null
 
EnterpriseDev


Guest


Hi, I have the following piece of code called from inside the ItemSend event that has failed a few times for individual users in rare instances with a null exception. Not sure which part is null, could be CurrentInstance, OutlookApp or Session. Restarting Outlook helps.

Have you seen this before? Is there anything I can do about it? detect the case and "try again" or something similar?

public static string GetExchangeConnectionModeStr()
		{
			Outlook.NameSpace session = null;

			try
			{
				session = AddinModule.CurrentInstance.OutlookApp.Session;

				switch (session.ExchangeConnectionMode)
				{
					case Outlook.OlExchangeConnectionMode.olCachedConnectedDrizzle: return "olCachedConnectedDrizzle";
					case Outlook.OlExchangeConnectionMode.olCachedConnectedFull: return "olCachedConnectedFull";
					case Outlook.OlExchangeConnectionMode.olCachedConnectedHeaders: return "olCachedConnectedHeaders";
					case Outlook.OlExchangeConnectionMode.olCachedDisconnected: return "olCachedDisconnected";
					case Outlook.OlExchangeConnectionMode.olCachedOffline: return "olCachedOffline";
					case Outlook.OlExchangeConnectionMode.olDisconnected: return "olDisconnected";
					case Outlook.OlExchangeConnectionMode.olNoExchange: return "olNoExchange";
					case Outlook.OlExchangeConnectionMode.olOffline: return "olOffline";
					case Outlook.OlExchangeConnectionMode.olOnline: return "olOnline";
				}
			}
			finally
			{
				if (session != null) Marshal.ReleaseComObject(session);
			}

			return "cannotFindConnectionMode";
		}
Posted 20 Sep, 2016 13:23:35 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello,

EnterpriseDev writes:
Not sure which part is null, could be CurrentInstance, OutlookApp or Session.


I suggest that you split that construct and check every part of it.


Andrei Smolin
Add-in Express Team Leader
Posted 21 Sep, 2016 00:58:17 Top
EnterpriseDev


Guest


This cannot be replicated in a development environment. It happens to only one user out of several thousands. That is why I am asking specifically about if you have seen any part of that statement fail before.
Posted 21 Sep, 2016 01:15:41 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
I can't remember such an issue. Splitting that construct should help finding the cause of the issue.

You can add a number of debug messages to your code; use System.Diagnostics.Debug.WriteLine(). You collect the messages at run time using DebugView (see http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx).


Andrei Smolin
Add-in Express Team Leader
Posted 21 Sep, 2016 01:58:17 Top