Form Region Leak in Visual Studio Tools for Office 2008 (v3) Template


I had a case on this a few months ago, but thought more folks might run into this as they start moving to form regions. By default, if you use the VSTO template for creating a form region in Outlook, the item is leaked. This can show up in a number of different symptoms, but the one we saw was that when the item was created (then saved and closed), then modified in WebDav, then they tried to modify the item again in Outlook, the user would get the error:

"The item cannot be saved because it was changed by another user or in a another window."

Fortunately, the resolution is easy, you just need to add a call to Marshal.ReleaseComObject to the FormRegionInitializing event in the designer code.

private void FormRegion1Factory_FormRegionInitializing(object sender, Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs e)
{
    Marshal.ReleaseComObject(e.OutlookItem);
}

Comments (5)

  1. Tobin Harris says:

    Hmmm, this is working for me, but it might be because I access the object on FormRegionShowing. I tried releasing it again there, but no cigar.

  2. Tobin Harris says:

    Hmmm, this is working for me, but it might be because I access the object on FormRegionShowing. I tried releasing it again there, but no cigar.

  3. pcreehan1 says:

    Make sure you are releasing all references to COM objects. If you still can’t figure it out, start removing sections of your code until the problem goes away. That might help you narrow down where your leak is. Again, the problem I described above was with no code, just the empty Form Region project.

    If you still can’t figure out where the leak is, you might want to open a support case with us.

  4. Recently, I was helping someone with a Outlook item leak type issue involving a Task FormRegion. 

Skip to main content