VSTO Com-add in prevents Outlook Notes from closing first time

R

Rowland Fong Lip

Hi

I have developed a C# com addin in VSTO 2005 / Office Professional 2003 and
deployed it to a XP pc with Office Standand 2003 (SP2 installed).

It all works fine except has this strange behaviour. If you create or open
an Outlook Note, you have to click on the X multiple times to close the item.

Has anyone experienced this before?

Thanks
Rowland
 
K

Ken Slovak - [MVP - Outlook]

I don't know if this has anything do with it but deploying a VSTO addin is
only supported for Office 2003 Professional or above. Also, are you doing
anything with any Notes objects (IPM.StickyNote)? Notes are brain dead and
never should be worked with in code.
 
P

PShah

Rowland / Ken

I have the exact same scenario as Rowland. Have a C# addin for Outlook
(using VSTO 2005 not SE) and using Outlook 2003 SP2.

Ken - In my case - there is no programming done for notes. It is more
like wiring up the inspectors_NewInspector and inside that i check if
item being opened is mail item. If it is then - all the logic but if
not then just do nothing. Notes ofcourse falls inside the else block.

Recently I opened a case with Microsoft regarding this and am
currently working with them on this issue.

It seems that this issue is a bug (not related to coding in C#). Also
with the above logic - there have been some issues with calender
items. Again as mentioned above - I dont program for calender items -
so they all fall in else block but it seems that the inspector doesnt
release the reference even though i force Garbage collection.

Code in the else block (if not mail Item)

{
Marshal.ReleaseComObject(inspector)
inspector = null;

GC.WaitForPendingFinalizers();
GC.Collect();
}

Rowland - it also seems that depending on the Outlook version you are
running - u see a flavour of this issue.
My own developement machine has Outlook version 11.8120.8122 SP2 and
when i try to click "x" multiple times on the note - it crashes
outlook and restarts.
A test machine has Outlook version 11.8120.8107 SP2 and there the
behavior is that I need to click "x" twice before it closes the note.
It doesnt crash Outlook.

On speaking to the MS representative - it seems that could be a bug in
the product (VSTO or Outlook) but they are still looking into it.

Rowland - have u also seen issues for calender items (i am assuming
that u are also working with mail items).

Regarding notes - i will update this chain if i get a fix and it
works.........

Thanks
 
K

Ken Slovak - [MVP - Outlook]

I don't understand.

Why are you releasing the Inspector object? It's local to the scope of
NewInspector. I use VSTO 2005 and VSTO 2005 SE and never had to release the
Inspector passed in NewInspector. I use Inspector wrapper classes to wrap
all Inspectors other than Notes usually, but that's a different story.

What exactly is your case with MS about?

The usual wisdom regarding programming Notes is don't do it, they're brain
dead. That goes back to the Outlook 97 days and hasn't changed at all. A
Notes.Inspector object is especially deadly.
 
P

PShah

Ken

So here is the code in the inspectors_NewInspector method (which is
wired up in the ThisApplication_Startup)


private void inspectors_NewInspector(Outlook.Inspector inspector)
{
try
{
Object objCurrentItem = inspector.CurrentItem;
if (objCurrentItem is Outlook.MailItem)
{
// Enters this if loop if the item is Mail Item and my
complete logic is here since my plugin
// only has programming done for MailItems
}
else
{
Marshal.ReleaseComObject (objCurrentItem);
objCurrentItem = null;

GC.WaitForPendingFinalizers( );
GC.Collect( );
}
}
catch (Exception ex)
{
// Logging to local Event Logs
}
}

So Ken - as you see from above code - everything which is not an
MailItem falls into the else block (calender items, notes) etc.

I Dont do any programming for notes and totally agree with you that
they are brain-dead.

But with the above code - any item which is not MailItem falls into
the else loop (notes, calender, tasks) and even though I am cleaning
up - apparently the notes still holds a reference for inspector and so
when I click on "x" - it does close the note. When i click multiple
times on the "x" it sometimes closes the note or even crashes Outlook

What are your thoughts....

Thanks
 
K

Ken Slovak - [MVP - Outlook]

I wouldn't release anything at all in NewInspector, it's just not needed and
probably will cause problems. I use late binding to get the Class of the
Inspector.CurrentItem using code like this:

object item = Inspector.CurrentItem;
Type _type;
_type = item.GetType();
object[] args = new Object[] { };
Outlook.OlObjectClass _class;

_class = (Outlook.OlObjectClass)_type.InvokeMember("Class",
BindingFlags.Public | BindingFlags.GetField | BindingFlags.GetProperty,
null, item, _args);

That lets me check the item.Class. If it's a type I want to handle I do so,
if not the NewInspector code does nothing else. It releases nothing. I don't
even release item, all that I do is surround the tests for Class in
try{}...catch{} blocks.
 
P

PS

Ken

I will definitely try your suggested code today and see the results.

For the notes case though - as I had mentioned above that I have a
case open with Microsoft - it has been boiled down to a bug. Below is
the exact MS response which I got yesterday:

mS Response:
I am working with the Dev team regarding the StickyNote close problem.
It appears to be an issue introduced by a backport we made in Outlook
2003 for a fix in Outlook 2007 regarding the Item_Close event. The
VSTO 2005 AddinLoader for Outlook 2003 is listening for the close
event on StickyNotes and canceling the close. I am awaiting some
research from the dev team and I will update you when I hear back from
them.

Thanks
 
P

PS

Sort of the final update which I got from MS:

Lot of discussion going between Outlook team and the VSTO team (after
we discovered the issue and pointed it to them) and they are planing
to roll the fix in a hotfix which might be relased in the near
future.

Hopefully that will resolve this issue.
 
K

Ken Slovak - [MVP - Outlook]

Good to know, thanks.




PS said:
Sort of the final update which I got from MS:

Lot of discussion going between Outlook team and the VSTO team (after
we discovered the issue and pointed it to them) and they are planing
to roll the fix in a hotfix which might be relased in the near
future.

Hopefully that will resolve this issue.

Thanks for following up. I'm not surprised that the fix in Outlook 2003
broke things. The documented result is listed in
http://support.microsoft.com/default.aspx?scid=kb;EN-US;929593 in the
section on Some methods no longer work in the Inspector.Close...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top