WordEditor is NULL RRS feed

  • Question

  • Hi,

    I have developed a Outlook addin using .net client framework 4 (VSTO Runtime Tools)

    Addin is built for Outlook 2007/2010

    Addin traps the appointment object, and inserts some formatted text in its body.

    Addin works fine on most of our setups (Win 7 64bit, Outlook 2010 x86), however on some machines (with same setup) the following piece of code breaks intermittently.

                     Outlook.Inspector inspector = Item.GetInspector;
                    Word.Document doc = inspector.WordEditor as Word.Document;

    inspector.WordEditor is getting null.

    Trapped exception says:

    System.NullReferenceException: Object reference not set to an instance of an object

    There is no exact pattern found in our logs, and its quite puzzling to debug.

    Any pointers for this.


    Thursday, May 2, 2013 2:28 PM


  • I find  two threads which is the similar with your issue.

    you will get some vb code snippets(in second reply) and then you can convert them to C# in below thread:

    The first reply said that :

    In Outlook 2007 you only get a weak object reference a newly opened
    Inspector until the first Activate() event fires on that Inspector. A weak
    object reference will only have a small subset of its properties filled out
    and valid. Among the properties not valid until that first Activate() are

    Depending on when your ribbon callback is firing would determine if you can
    get a valid document object as you want.

    What I usually do is to instantiate the WordEditor object in the first
    Activate() and make it available as a public property on my Inspector
    wrapper class. I also call to invalidate the ribbon in that event and at
    that point I can get the relevant wrapper class and pick up any properties I
    need, including WordEditor.

    If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample

    Thursday, May 2, 2013 2:59 PM