none
Outlook 2003 - sending a word-mail causes "operation cannot be performed because the object has been deleted"

    Question

  • Hi,

    I've created an add-on that captures a certain mail does some actions on it before sending (i register to outlook's send event and after finished my manipulations i call the send event itself). The problem occurs when i have a word-mail object. I've used ken's other posts and have 2 different implementations : one for a normal mail, and another for word-mail.

    Specifically the problem occurs in the send event which i override - i transfer the mailitem to a different folder. In normal outlook the item is moved and then the inspector is closed. in wordmail the item is moved but then on closing (i think it happens there) i get the "operation cannot be performed becuase the object has been deleted". i've tried to save the references of the word window itself to no avail. Furthermore, i tried to catch the error in the move and force the closing of the inspector (using inspector.close method) but again the exception arises.

    In general, My implementation of wordmail handler is - i have a wrapper for every inspector which in case it is wordmail i add it to a hashtable which holds a unique id and the wrapper itself (because of other problems ppl encountered with event handling in wordmail). then in the send i get the wrapper itself and use the inner mailitem.

    Hope i've made myself clear,

    thanks,

    garkler

    Monday, July 19, 2010 11:06 AM

Answers

  • That's a complex setup, and one that would be hard to keep track of. Why not handle both the item and Inspector in one wrapper class? That makes things a lot easier to keep track of. In my wrapper classes I have both Inspector and MailItem (or whatever item type I'm handling) objects and all the event handlers for the item and Inspector. Then I store the classes in a list to keep them alive.

    When Inspector.Close() or item.Close() fires I make sure to call my release code to remove the wrapper class from the list, and I release all event handlers and objects declared in the wrapper class. That makes it easy to keep track of things.


    Ken Slovak MVP - Outlook
    Thursday, July 22, 2010 2:34 PM

All replies

  • Are you releasing all of your referenced objects? I've usually seen that exception where something is still hanging around. You can't force a call to Close() in the Send() event, but you can set a timer that fires very soon after that event ends, and in the timer event handler you can make your call to Close().

    --
    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
     
     
    "garkler" <=?utf-8?B?Z2Fya2xlcg==?=> wrote in message news:6985aad7-d361-4f0b-8de9-16ce0cc37183...

    Hi,

    I've created an add-on that captures a certain mail does some actions on it before sending (i register to outlook's send event and after finished my manipulations i call the send event itself). The problem occurs when i have a word-mail object. I've used ken's other posts and have 2 different implementations : one for a normal mail, and another for word-mail.

    Specifically the problem occurs in the send event which i override - i transfer the mailitem to a different folder. In normal outlook the item is moved and then the inspector is closed. in wordmail the item is moved but then on closing (i think it happens there) i get the "operation cannot be performed becuase the object has been deleted". i've tried to save the references of the word window itself to no avail. Furthermore, i tried to catch the error in the move and force the closing of the inspector (using inspector.close method) but again the exception arises.

    In general, My implementation of wordmail handler is - i have a wrapper for every inspector which in case it is wordmail i add it to a hashtable which holds a unique id and the wrapper itself (because of other problems ppl encountered with event handling in wordmail). then in the send i get the wrapper itself and use the inner mailitem.

    Hope i've made myself clear,

    thanks,

    garkler


    Ken Slovak MVP - Outlook
    Monday, July 19, 2010 1:26 PM
  • Hi Ken,

    Thanks alot for your answer, i will try this workaround if i don't find a cleaner solution.

    but, i would like to understand a certain point a bit further - 

    If the error i get is the object has been deleted already shouldn't that mean that i mistakingly erase an object/reference that i shouldn't have?

    perhaps i'm missing something..

     

    thanks !

    garkler

    Thursday, July 22, 2010 1:50 PM
  • If you call the Move() method on an item then you get back a reference to the new item, and the old item is "deleted or moved". So any further references to the original item that haven't been updated to the new item will fire an exception such as the ones you are seeing.

    Does that explain the problem?


    Ken Slovak MVP - Outlook
    Thursday, July 22, 2010 2:08 PM
  • Hi, thanks again.

    I've checked my references - The point is i have many references to different items and i would like to be sure which ones you think affect this error -

    I have a wrapper for the inspector, a wrapper for the mail item, and a wrapper that holds both the mail item and the inspector.

    in the case of wordmail i have a static class that holds a list of all the wrappers that hold both.

    so i need to release all these references ?

     

    thanks,

    garkler

    Thursday, July 22, 2010 2:24 PM
  • That's a complex setup, and one that would be hard to keep track of. Why not handle both the item and Inspector in one wrapper class? That makes things a lot easier to keep track of. In my wrapper classes I have both Inspector and MailItem (or whatever item type I'm handling) objects and all the event handlers for the item and Inspector. Then I store the classes in a list to keep them alive.

    When Inspector.Close() or item.Close() fires I make sure to call my release code to remove the wrapper class from the list, and I release all event handlers and objects declared in the wrapper class. That makes it easy to keep track of things.


    Ken Slovak MVP - Outlook
    Thursday, July 22, 2010 2:34 PM
  • Hi ken, thanks a lot for your reply i eventually found the problem.

    I do have 2 other questions which i've been trying to solve for sometime now and can't seem to understand if this is an outlook bug or not.

    1. I register to the mail item's send event (in order to do as you described - move the item aside and perform my actions) and then use the send event itself. In wordmail i've noticed something weird - even though i catch the event and set cancel = true, 2 mails are being sent ; the original email without my mainpulation and another email which is the one i've handeled. what could be the issue?

    2. Again, in our friendly wordmail - i have an additional button that performs the attach function, i use my wrappers where each has its own unique id which is also saved as a property in the MailItem properties themselves, so that when the button is pressed i check the active inspectors id and get my wrapper (from the wrapper collection). The problem occurs when i have more than 3 inspectors open , then it seems that the ActiveInspector isn't always accurate and at times stays on the old inspector and so the attachments reach the wrong inspector. Is this an outlook bug ?

     

    thanks !

    garkler

    Monday, August 30, 2010 8:29 AM
  • I have no idea what's wrong with the first problem. When I cancel a send it gets cancelled. You have to look at your code and make sure you aren't sending separately and that the cancel is actually being set to true.

    For the second problem, don't always rely on ActiveInspector. Since you have properties where you can check for the correct Inspector without using ActiveInspector check the Inspectors collection to find the correct item.

     


    Ken Slovak MVP - Outlook
    Monday, August 30, 2010 12:50 PM