MailItem.GetInspector slow

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

MailItem.GetInspector slow
 
Fabrice Durieu


Guest


Hello

I've some generic code that try to get the inspector. This code is also run when I select a mail in the list of email (so not an open email, but a mail in an explorer).
So I would expect the code to return null, but it throw an exception. Throwing an exception is also not a problem (with Outlook Im used to..), as soon as I know it.
But my main problem is that it takes 5-600ms just to throw the exception, and the stack trace show that it's an exception thrown from Add-in express code. The stack trace let me think that a new inspector is created (?)

/!\ I use an old version of ADX, I still should update (since ...). Used version: 8.0.4330.0. So maybe it's now fixed (?)

My code:

public static Outlook.Inspector GetInspector(this Outlook.MailItem m)
{
	if (m != null)
	{
		try
		{
			return m.GetInspector as Outlook.Inspector;
		}
		catch { /* Outlook can throw an exception if the mail doesn't have any inspector yet */ }
	}

	return null;
}


The triggered exception:

System.Runtime.InteropServices.COMException (0x80020006): Nom inconnu. (Exception de HRESULT : 0x80020006 (DISP_E_UNKNOWNNAME))
   à System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   à System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)


Error can be translated to "Unknow Name"

And the thread stacktrace:


AddinExpress.MSO.2005.dll!AddinExpress.MSO.ADXAddinModule.GetFullFolderName(object folder, bool clearFolderInterface)	Unknown
AddinExpress.MSO.2005.dll!AddinExpress.MSO.ADXAddinModule.OlInspectorEvents_BaseLogic.ConnectTo(object inspector, object events)	Unknown
AddinExpress.MSO.2005.dll!AddinExpress.MSO.ADXAddinModule.OlInspectorsEvents_SinkHelper.DoNewInspector(object sender, object inspector)	Unknown
AddinExpress.MSO.2005.dll!AddinExpress.MSO.ADXAddinModule.OlInspectorsEvents_SinkHelper.AddinExpress.MSO.IInspectorsEvents.NewInspector(object inspector)	Unknown
[Native to Managed Transition]	
[Managed to Native Transition]	
[Native to Managed Transition]	
[Managed to Native Transition]	
MyNamespace.MailItemExtensions.GetInspector(Microsoft.Office.Interop.Outlook.MailItem m) Line 146	C#




A part from that, if you know how I can avoid calling GetInspector if there is no inspector it could also solve the problem.

Thank you for your help.
Posted 30 Oct, 2018 10:41:49 Top
Andrei Smolin


Add-in Express team


Posts: 18794
Joined: 2006-05-11
Hello Fabrice,

You are right: the GetInspector call returns or creates an Inspector object. If you do not need to create an inspector, you need to scan the Inspectors collection and check every Inspector.CurrentItem.


Andrei Smolin
Add-in Express Team Leader
Posted 31 Oct, 2018 06:11:01 Top