none
Microsoft.Office.Interop.Outlook.Application ItemEvents_10_WriteEventHandler firing multiple times RRS feed

  • Question

  • We have an application that uses interop with Outlook to manage 'Post' items.  The application subscribes to the ItemEvents_10_WriteEventHandler.  In the previous version of Microsoft.Office.Interop.Outlook.dll this event fired once and only once each time a post item was created, and only once the user selected 'post item'

    However in a recent windows update this DLL (now version 14) seems to be firing as soon as the post item is created (i.e. not written yet - user has not selected 'post item').  Since the signature for this event does not provide a sender we have no way of interogating the object to find out why the write is firing.

    Does anyone have any idea regarding this apparent change in the write event firing?

    Tuesday, October 1, 2013 8:40 PM

All replies

  • Hi Geoff,

    I failed to reproduce your issue in Outlook 2010.

    Code:

    public partial class Form1 : Form
        {
            dynamic outlook;
            Outlook.Inspectors inspectors;
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                outlook= Activator.CreateInstance(Type.GetTypeFromProgID("Outlook.Application"));
    
               inspectors = outlook.Inspectors;
               inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
            }
    
            private void Inspectors_NewInspector(Outlook.Inspector Inspector)
            {
                if (Inspector.CurrentItem is Outlook.PostItem)
                {
                    Outlook.PostItem postItem = Inspector.CurrentItem;
                    postItem.Write += postItem_Write;
                }
            }
    
            void postItem_Write(ref bool Cancel)
            {
                MessageBox.Show("hello");
            }
    
    }
    

    Steps:

    1. Run outlook 2010
    2. Run form application
    3. Create a post item in outlook
    4. Write and save post item

    Please correct me if I have any misunderstanding.

    What’s the version of your Outlook application? Could you provide us some code snippet to reproduce the issue?

    Best Regards

    Fei

     


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, October 2, 2013 1:42 PM
    Moderator
  • Thanks for the reply Fei.

    I tried your code on my machine. As is, the code only fires the write event once.  However we are creating the PostItem programmatically from the application.  I added the following to your code:

            private void button1_Click(object sender, EventArgs e)

            {

                PostItem newPostItem = (PostItem)outlook.CreateItem(OlItemType.olPostItem);

                if (newPostItem == null)

                {

                    MessageBox.Show("Failed to create an outlook Post Item");

                    return;

                }

                newPostItem.Display(false);

            }

    ... and now it fires twice. Once as the post item is instantiated (which makes no sense) and once the user clicks post.  The only two DLLs that we can see related to this is the (Microsoft.Office.Code) or Office.dll and the (Microsoft.Office.Interop.Outlook) or Microsoft.Office.Interop.Outlook.dll

    We have about 650 systems in production and this problem started about 10 days ago.  I was assuming this was related to an update that was performed by the automated system (WSUS), but comparing the DLLs from a working and non-working system they seem to be the same (i.e. binary size, version, date, etc.)

    We have also confirmed that if you uninstall Outlook 2010 and re-install it will work fine for about 24 hours and then the problem re-appears.

    Can you verify if adding the code above on your system (i.e. create the post item in the proc space of the application) causes the write event to fire twice?

    This is a strange one.

    Wednesday, October 2, 2013 9:26 PM
  • I'm going to call this one into MS Dev Support and see if they can access the Outlook source to determine why this behaviour change...
    Wednesday, October 9, 2013 4:17 PM
  • We had a similar problem with our Outlook 2010 Add-in too, where the Write event started firing (incorrectly) when we called Display() on an Outlook Item or Activate() on an Inspector. The problem began around the same time too - October 2013. We would be interested in hearing if a solution or workaround was found...

    Thanks

    Wednesday, January 8, 2014 9:59 PM
  • We finally had to open a call to MS Support (via MSDN) after we discovered that this is a direct result of two patches released by MS (we use WSUS).  If you uninstall these two patches the problem is resolved.  However since they are security patches we dont want to remove from production and thus we are looking for MS to fix the event issue ASAP.

    The two patches in question are:
    2794707 and 2837597, 2837597 supersedes 2794707 but the problem still exists

    We are still in progress with MS Support.  I'll update when (and assuming) we get to an "end game" solution with them.

    Wednesday, January 8, 2014 10:13 PM