Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Outlook new inspector event not firing

364 views
Skip to first unread message

ramz_g

unread,
Dec 21, 2009, 11:16:01 AM12/21/09
to
Hi,
I have developed an add-in for Outlook which adds a menu to the Outlook
menubar.
I have also registered the Outlook.NewInspector event. This event fires
without any problem when I click on "New" as soon as I open Outlook...
However, if I click on "New" after clicking on any of the items in my add-in
menu, the Outlook.NewInspector is not getting fired... Can anyone pls shed
some light on why this is happening?

Thanks,
Ram

Ken Slovak - [MVP - Outlook]

unread,
Dec 21, 2009, 11:42:49 AM12/21/09
to
This is just a guess since you didn't show the code you use to declare the
event handler and didn't provide much information such as Outlook version or
language used.

Are you declaring an Inspectors collection object at a class level that
won't get garbage collected? If not, and I suspect the answer is no, that's
what's happening to your event handler.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"ramz_g" <ra...@discussions.microsoft.com> wrote in message
news:E2EF2433-A46E-4CD5...@microsoft.com...

ramz_g

unread,
Dec 21, 2009, 12:54:02 PM12/21/09
to
Hi Ken,

Just as I posted this question, I found a similar problem being discussed in
a different forum.. And yes, I hadnt declared the Inspectors collection
object at the class level... After I did it, my code is working fine..

Thanks a lot for your reply...

Thanks,
Ram

> .
>

Nad Cc

unread,
Sep 15, 2010, 5:10:28 AM9/15/10
to
Hi I have the same error, Here's my code:

namespace OC_MX
{
using System;
using System.Runtime.InteropServices;
//using System.Windows.Forms;
using OCServer;
using Outlook = Microsoft.Office.Interop.Outlook;


[GuidAttribute("33B2620D-CF67-44F3-A25D-C61B2B25A57D"), ProgId("OutlookCRM_MX.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
#region constructor

public Connect()
{
CLogger.WriteLog(ELogLevel.INFO, "Construtor - Begin");
addin = new OutlookAddin();

CLogger.WriteLog(ELogLevel.INFO, "Construtor - End");
}
#endregion

#region AddInBasicTriggers

public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
try
{
CLogger.WriteLog(ELogLevel.INFO, "OnConnection - Begin");
applicationObject = (Microsoft.Office.Interop.Outlook.Application)application;
addInInstance = addInInst;
InspectorMailItem = applicationObject.Inspectors;

InspectorMailItem.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(addin.Inspectors_NewInspector);

addin.OnConnection(application, connectMode, addInInst, ref custom);

if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}

CLogger.WriteLog(ELogLevel.INFO, "OnConnection - End");
}
catch (System.Exception ex)
{ CLogger.WriteLog(ELogLevel.ERROR, "OnConnection - Exception= " + ex.Message); }
}


public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom)
{
CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - Begin");
addin.onDisconnection();
if (disconnectMode != Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref custom);
}
CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - End");
CLogger.WriteLog(ELogLevel.INFO, "************************************************************************************************************************************************************* - End");
}

public void OnStartupComplete(ref System.Array custom)
{
CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - Begin");

addin.startup();
CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - End");
}

public void OnBeginShutdown(ref System.Array custom)
{
CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - Begin");
addin.onBeginShutdown();
CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - End");
CLogger.WriteLog(ELogLevel.INFO, "**********************************************************************************************************");
}

//event triggered when item is opened
private void Inspectors_NewInspector(Outlook.Inspector i)
{
System.Windows.Forms.MessageBox.Show("inspector");

}

#endregion

OutlookAddin addin;
private Outlook.Inspectors InspectorMailItem;//InspectorMailitem must be declared at class level. If Not, the event NewInspector may not be launched when any item is opened;
private Outlook.Application applicationObject;
private object addInInstance;
}
}

I am using Microsoft.Office.Interop.Outlook 10.0.4504.0 FOR COMPATIBILITY ISSUES with lookout.

Can you help me please?

Thanks,
NadCC


> On Monday, December 21, 2009 11:16 AM ramz_g wrote:

> Hi,
> I have developed an add-in for Outlook which adds a menu to the Outlook
> menubar.
> I have also registered the Outlook.NewInspector event. This event fires
> without any problem when I click on "New" as soon as I open Outlook...
> However, if I click on "New" after clicking on any of the items in my add-in
> menu, the Outlook.NewInspector is not getting fired... Can anyone pls shed
> some light on why this is happening?
>
> Thanks,
> Ram


>> On Monday, December 21, 2009 11:42 AM Ken Slovak - [MVP - Outlook] wrote:

>> This is just a guess since you did not show the code you use to declare the
>> event handler and did not provide much information such as Outlook version or


>> language used.
>>
>> Are you declaring an Inspectors collection object at a class level that

>> will not get garbage collected? If not, and I suspect the answer is no, that is
>> what is happening to your event handler.


>>
>> --
>> Ken Slovak
>> [MVP - Outlook]
>> http://www.slovaktech.com
>> Author: Professional Programming Outlook 2007.
>> Reminder Manager, Extended Reminders, Attachment Options.
>> http://www.slovaktech.com/products.htm


>>> On Monday, December 21, 2009 12:54 PM ramz_g wrote:

>>> Hi Ken,
>>>
>>> Just as I posted this question, I found a similar problem being discussed in
>>> a different forum.. And yes, I hadnt declared the Inspectors collection
>>> object at the class level... After I did it, my code is working fine..
>>>
>>> Thanks a lot for your reply...
>>>
>>> Thanks,
>>> Ram
>>>
>>> "Ken Slovak - [MVP - Outlook]" wrote:


>>> Submitted via EggHeadCafe - Software Developer Portal of Choice
>>> Lucene.Net Indexing Searching Entry Level Tutorial
>>> http://www.eggheadcafe.com/tutorials/aspnet/c69ef65f-e3c6-409e-ab97-168897c74f83/lucenenet-indexing-searching-entry-level-tutorial.aspx

Nad Cc

unread,
Sep 15, 2010, 5:11:00 AM9/15/10
to

#region AddInBasicTriggers

InspectorMailItem.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(addin.Inspectors_NewInspector);

}

Thanks,
NadCC

> Hi,
> I have developed an add-in for Outlook which adds a menu to the Outlook
> menubar.
> I have also registered the Outlook.NewInspector event. This event fires
> without any problem when I click on "New" as soon as I open Outlook...
> However, if I click on "New" after clicking on any of the items in my add-in
> menu, the Outlook.NewInspector is not getting fired... Can anyone pls shed
> some light on why this is happening?
>
> Thanks,
> Ram

>> On Monday, December 21, 2009 11:42 AM Ken Slovak - [MVP - Outlook] wrote:

>> This is just a guess since you did not show the code you use to declare the
>> event handler and did not provide much information such as Outlook version or


>> language used.
>>
>> Are you declaring an Inspectors collection object at a class level that

>> will not get garbage collected? If not, and I suspect the answer is no, that is
>> what is happening to your event handler.


>>
>> --
>> Ken Slovak
>> [MVP - Outlook]
>> http://www.slovaktech.com
>> Author: Professional Programming Outlook 2007.
>> Reminder Manager, Extended Reminders, Attachment Options.
>> http://www.slovaktech.com/products.htm

>>> On Monday, December 21, 2009 12:54 PM ramz_g wrote:

>>> Hi Ken,
>>>
>>> Just as I posted this question, I found a similar problem being discussed in
>>> a different forum.. And yes, I hadnt declared the Inspectors collection
>>> object at the class level... After I did it, my code is working fine..
>>>
>>> Thanks a lot for your reply...
>>>
>>> Thanks,
>>> Ram
>>>
>>> "Ken Slovak - [MVP - Outlook]" wrote:

>>>> Submitted via EggHeadCafe - Software Developer Portal of Choice

>>>> MongoDb vs SQL Server Basic Speed Tests
>>>> http://www.eggheadcafe.com/tutorials/aspnet/6f573869-c8eb-40c3-9946-2f61e0163966/mongodb-vs-sql-server-basic-speed-tests.aspx

Nad Cc

unread,
Sep 15, 2010, 5:12:52 AM9/15/10
to

#region AddInBasicTriggers

InspectorMailItem.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(addin.Inspectors_NewInspector);

}

Thanks,
NadCC

> Hi,
> I have developed an add-in for Outlook which adds a menu to the Outlook
> menubar.
> I have also registered the Outlook.NewInspector event. This event fires
> without any problem when I click on "New" as soon as I open Outlook...
> However, if I click on "New" after clicking on any of the items in my add-in
> menu, the Outlook.NewInspector is not getting fired... Can anyone pls shed
> some light on why this is happening?
>
> Thanks,
> Ram

>> On Monday, December 21, 2009 11:42 AM Ken Slovak - [MVP - Outlook] wrote:

>> This is just a guess since you did not show the code you use to declare the
>> event handler and did not provide much information such as Outlook version or


>> language used.
>>
>> Are you declaring an Inspectors collection object at a class level that

>> will not get garbage collected? If not, and I suspect the answer is no, that is
>> what is happening to your event handler.


>>
>> --
>> Ken Slovak
>> [MVP - Outlook]
>> http://www.slovaktech.com
>> Author: Professional Programming Outlook 2007.
>> Reminder Manager, Extended Reminders, Attachment Options.
>> http://www.slovaktech.com/products.htm

>>>>> Composite UI Pattern and RAD Development for Data Entry Applications, Part 1
>>>>> http://www.eggheadcafe.com/tutorials/aspnet/a119aebe-7478-4aaa-b415-12786ec5cf90/composite-ui-pattern-and-rad-development-for-data-entry-applications-part-1.aspx

Nad Cc

unread,
Sep 15, 2010, 5:13:15 AM9/15/10
to

#region AddInBasicTriggers

InspectorMailItem.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(addin.Inspectors_NewInspector);

}

Thanks,
NadCC

> Hi,
> I have developed an add-in for Outlook which adds a menu to the Outlook
> menubar.
> I have also registered the Outlook.NewInspector event. This event fires
> without any problem when I click on "New" as soon as I open Outlook...
> However, if I click on "New" after clicking on any of the items in my add-in
> menu, the Outlook.NewInspector is not getting fired... Can anyone pls shed
> some light on why this is happening?
>
> Thanks,
> Ram

>> On Monday, December 21, 2009 11:42 AM Ken Slovak - [MVP - Outlook] wrote:

>> This is just a guess since you did not show the code you use to declare the
>> event handler and did not provide much information such as Outlook version or


>> language used.
>>
>> Are you declaring an Inspectors collection object at a class level that

>> will not get garbage collected? If not, and I suspect the answer is no, that is
>> what is happening to your event handler.


>>
>> --
>> Ken Slovak
>> [MVP - Outlook]
>> http://www.slovaktech.com
>> Author: Professional Programming Outlook 2007.
>> Reminder Manager, Extended Reminders, Attachment Options.
>> http://www.slovaktech.com/products.htm

>>>>>> Silverlight Binary Serialization and Compression with WCF Services
>>>>>> http://www.eggheadcafe.com/tutorials/aspnet/96487d4c-d92f-4ca5-85b7-0fef6f42d6c3/silverlight-binary-serialization-and-compression-with-wcf-services.aspx

Ken Slovak

unread,
Sep 15, 2010, 9:06:08 AM9/15/10
to
No need to post 4 times.

Did you bother to look at the answer the previous poster received? Your
problem has the exact same cause, you aren't declaring an Inspectors
collection object at class level and adding the event handler to that
object. So your handler goes out of scope when OnConnection() ends and your
handler gets garbage collected.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Nad Cc" <nadine...@hotmail.com> wrote in message
news:201091551...@eggheadcafe.com...

nadcc

unread,
Sep 15, 2010, 10:35:53 AM9/15/10
to
Ken Slovak - [MVP - Outlook] wrote on 12/21/2009 11:42 ET :
> This is just a guess since you didn't show the code you use to declare the
> event handler and didn't provide much information such as Outlook version or
> language used.
>
> Are you declaring an Inspectors collection object at a class level that
> won't get garbage collected? If not, and I suspect the answer is no, that's
> what's happening to your event handler.
>
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> &quot;ramz_g&quot; wrote in message
> news:

>> Hi,
>> I have developed an add-in for Outlook which adds a menu to the Outlook
>> menubar.
>> I have also registered the Outlook.NewInspector event. This event fires
>> without any problem when I click on &quot;New&quot; as soon as I open
>> Outlook...
>> However, if I click on &quot;New&quot; after clicking on any of the items in

>> my
>> add-in
>> menu, the Outlook.NewInspector is not getting fired... Can anyone pls shed
>> some light on why this is happening?
>>
>> Thanks,
>> Ram
>>
>>
>
Hi Ken,

I am having the same problem. Here's my code:


namespace OC_MX
{
using System;
using System.Runtime.InteropServices;
using OCServer;
using Outlook = Microsoft.Office.Interop.Outlook;

[GuidAttribute(&quot;33B2620D-CF67-44F3-A25D-C61B2B25A57D&quot;),
ProgId(&quot;OutlookCRM_MX.Connect&quot;)]

public class Connect : Object, Extensibility.IDTExtensibility2
{
#region constructor
public Connect()
{
CLogger.WriteLog(ELogLevel.INFO, &quot;Construtor - Begin&quot;);
addin = new OutlookAddin();
CLogger.WriteLog(ELogLevel.INFO, &quot;Construtor - End&quot;);
}
#endregion


public void OnConnection(object application, Extensibility.ext_ConnectMode
connectMode, object addInInst, ref System.Array custom)
{
try
{
CLogger.WriteLog(ELogLevel.INFO, &quot;OnConnection - Begin&quot;);

applicationObject = (Microsoft.Office.Interop.Outlook.Application)application;
addInInstance = addInInst;
InspectorMailItem = applicationObject.Inspectors;

InspectorMailItem.NewInspector += new

Outlook.InspectorsEvents_NewInspectorEventHandler(addin.Inspectors_NewInspector);

addin.OnConnection(application, connectMode, addInInst, ref custom);

if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}

CLogger.WriteLog(ELogLevel.INFO, &quot;OnConnection - End&quot;);
}
catch (System.Exception ex)
{ CLogger.WriteLog(ELogLevel.ERROR, &quot;OnConnection - Exception= &quot; +


ex.Message); }
}

public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode,
ref
System.Array custom)
{

addin.onDisconnection();
if (disconnectMode != Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref custom);
}
}


public void OnStartupComplete(ref System.Array custom)
{

CLogger.WriteLog(ELogLevel.INFO, &quot;OnStartupComplete - Begin&quot;);
addin.startup();
CLogger.WriteLog(ELogLevel.INFO, &quot;OnStartupComplete - End&quot;);


}


public void OnBeginShutdown(ref System.Array custom)
{

//...


}

//event triggered when item is opened
private void Inspectors_NewInspector(Outlook.Inspector i)
{

System.Windows.Forms.MessageBox.Show(&quot;inspector&quot;);



}


OutlookAddin addin;
private Outlook.Inspectors InspectorMailItem;//InspectorMailitem must be
declared at class level. If Not, the event NewInspector may not be launched
when
any item is opened;
private Outlook.Application applicationObject;
private object addInInstance;
}
}

I am using Microsoft.Office.Interop.outlook 10.0.4504.0 for compatibility
reasons with lookout.



Can you help me please?

Thanks,

nc

Ken Slovak

unread,
Sep 15, 2010, 10:53:32 AM9/15/10
to
I don't know what else you need, you already know that you need to declare
your Inspectors collection at class level and not in your OnConnection()
code. Just do it and the even will fire correctly.

// this is at class level, before any procedures
Outlook.Inspectors whateverYouFeelLikeNamingTheInspectorsCollection = null;
// now assign your event handler to whatever you named your Inspectors
object in OnConnection()

--

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"nadcc" <na...@domain-xyz.in> wrote in message
news:LYadneASe5x...@giganews.com...
<snip>

Nad Cc

unread,
Sep 16, 2010, 6:58:54 AM9/16/10
to
Hi Ken,

Thank you for your quick answer and patience. the new inspector is firing but I try to add a button through this newinspector handler and the code contains commandbars, the new inspector stops firing:

here's my code:


private void Inspectors_NewInspector(Outlook.Inspector i)
{
System.Windows.Forms.MessageBox.Show("inspector");

string messageClass = "";

if (i.CurrentItem is Outlook.MailItem)
{
mitem = i.CurrentItem as Outlook.MailItem;
messageClass = mitem.MessageClass;
}

Outlook.Selection outlookSelection = applicationObject.ActiveExplorer().Selection;

/****************/
/****************/
/****************/
/****************/
try
{
oCommandBars = i.CommandBars;
}

catch (System.Exception)
{
// Outlook has the CommandBars collection on the Explorer object.
object oActiveExplorer;
oActiveExplorer = applicationObject.GetType().InvokeMember("ActiveExplorer", BindingFlags.GetProperty, null, applicationObject, null);

oCommandBars = (CommandBars)oActiveExplorer.GetType().InvokeMember("CommandBars", BindingFlags.GetProperty, null, oActiveExplorer, null);
}

// Set up a custom button on the "Standard" commandbar.
try
{
oStandardBar = oCommandBars["Standard"];
}

catch (System.Exception)
{
oStandardBar = oCommandBars["Database"];
}

/****************/
/****************/
/****************/
/****************/


if (outlookSelection.Count > 0)
{
object omissing = System.Reflection.Missing.Value;
selectedItem = outlookSelection[1];
if (selectedItem is Outlook.MailItem)
{
if (messageClass == "IPM.Note")
{
selectedmsg = (selectedItem as Outlook.MailItem);

selectedmsg.Read += new Outlook.ItemEvents_10_ReadEventHandler(Read_Mail);
selectedmsg.Open += new Outlook.ItemEvents_10_OpenEventHandler(Open_Mail);


Word.Document document = (Word.Document)i.WordEditor;
if (mxcrm == true && document.Kind.ToString().Equals("wdDocumentEmail") && this.applicationObject.ActiveExplorer().Application.Name.Equals("Outlook"))
addsendbutton();
}


}

}
}

private void Open_Mail(ref bool cancel)
{
CLogger.WriteLog(ELogLevel.INFO, "Open_Mail - Begin");
CommandBarControls controls = oStandardBar.Controls;
//remove old menus...

foreach (CommandBarControl control in controls)
{
String caption = control.Caption;
if (caption.EndsWith("MxCRM") || caption.EndsWith("Send and Upload to CRM"))
{
control.Delete(null);
}
}

try
{
addpopupandbutton();
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show("Exception= " + ex.Message);
}
CLogger.WriteLog(ELogLevel.INFO, "Open_Mail - End");
}

private void Read_Mail()
{
CLogger.WriteLog(ELogLevel.INFO, "Read_Mail - Begin");
CommandBarControls controls = oStandardBar.Controls;

//remove old menus...
foreach (CommandBarControl control in controls)
{
String caption = control.Caption;
if (caption.EndsWith("MxCRM"))
{
control.Delete(null);
}
}

CLogger.WriteLog(ELogLevel.INFO, "Read_Mail - End");

}

public CommandBars oCommandBars;
public CommandBar oStandardBar;//at class level


When I remove the part of the code surrounded by the stars /****************/, the new inspector gets fired. the same problem appears if I put the star code in openmail or read mail, then the open and read dont fire anymore. the part surrounded by /****************/ is important to add the button on the commandbar of the mailitem.

Any idea what I am missing here or doing wrong? I am very new to this field.

Thanks a lot,
Nc

Submitted via EggHeadCafe - Software Developer Portal of Choice

Simple .NET HEX PixelColor Utility
http://www.eggheadcafe.com/tutorials/aspnet/5617a491-963d-4510-b8f1-1863ddf52bc1/simple-net-hex-pixelcolor-utility.aspx

Ken Slovak

unread,
Sep 16, 2010, 9:44:35 AM9/16/10
to
I have no idea why you're accessing Explorer commandbars in NewInspector(),
and if Office 2007 or higher is involved you need to set up to use the
ribbon, unless you like the lack of discoverability in the AddIns tab.

In general you get what's called a weak object reference in NewInspector().
It really shouldn't be used except for checking .CurrentItem.Class or
MessageClass, or checking the item type. Where you get a strong object
reference is in the first Inspector.Activate() event. I always add
commandbar UI to an Inspector in that event handler.

So, why are you accessing the Explorer commandbars?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm

"Nad Cc" <nadine...@hotmail.com> wrote in message

news:201091665...@eggheadcafe.com...

0 new messages