<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>mstehle: The CDOs and CDONTS of Messaging Development : VSTO</title><link>http://blogs.msdn.com/mstehle/archive/tags/VSTO/default.aspx</link><description>Tags: VSTO</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>FYI:  Issue with Windows 7 RC and VSTO…</title><link>http://blogs.msdn.com/mstehle/archive/2009/06/02/fyi-issue-with-windows-7-rc-and-vsto.aspx</link><pubDate>Tue, 02 Jun 2009 20:15:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9686004</guid><dc:creator>mstehle</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/mstehle/comments/9686004.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mstehle/commentrss.aspx?PostID=9686004</wfw:commentRss><wfw:comment>http://blogs.msdn.com/mstehle/rsscomments.aspx?PostID=9686004</wfw:comment><description>&lt;p&gt;The &lt;a href="http://blogs.msdn.com/vsto/archive/2009/05/07/issues-with-installing-vsto-projects-that-were-published-from-visual-studio-2008-on-windows-7-rc-saurabh-bhatia.aspx"&gt;VSTO team has a post&lt;/a&gt; which details an issue that you might see when trying to deploy a VSTO solution to Windows 7 RC.&amp;#160; The error message would be…&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;“The required version of the .NET Framework is not installed on this computer”&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;As the blog post points out, the appropriate teams are aware of the issue and plan to address it by RTM of Windows 7.&amp;#160; Additionally they provide a workaround in the meantime.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9686004" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mstehle/archive/tags/DevMsgTeam/default.aspx">DevMsgTeam</category><category domain="http://blogs.msdn.com/mstehle/archive/tags/VSTO/default.aspx">VSTO</category></item><item><title>OOM.NET: Like a good standup comic – use scope and have good timing…</title><link>http://blogs.msdn.com/mstehle/archive/2009/02/17/oom-net-like-a-good-standup-comic-use-scope-and-have-good-timing.aspx</link><pubDate>Tue, 17 Feb 2009 18:55:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9427731</guid><dc:creator>mstehle</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/mstehle/comments/9427731.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mstehle/commentrss.aspx?PostID=9427731</wfw:commentRss><wfw:comment>http://blogs.msdn.com/mstehle/rsscomments.aspx?PostID=9427731</wfw:comment><description>&lt;p&gt;Recently, I was helping someone with a Outlook item leak type issue involving a Task FormRegion.&amp;#160; The symptom was that after opening a task, closing it, and reopening the item they were getting the infamous error message, “COM object that has been separated from its underlying RCW cannot be used.”&amp;#160; They were familiar with some of the issues discussed here and knew to call &lt;em&gt;ReleaseCOMObject()&lt;/em&gt; on objects as they were done with them.&amp;#160; However, that is the only part of proper Outlook coding with .NET – you need to use scope and have good timing when you lay out .NET classes that handle events and use Outlook objects.&amp;#160; The following class is a simple example of that scope and timing…&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Scope&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;As I pointed out in &lt;a href="http://blogs.msdn.com/mstehle/archive/2007/12/06/oom-net-part-1-introduction-why-events-stop-firing.aspx" target="_blank"&gt;my original OOM.NET post&lt;/a&gt;, you need to consider the scope of the objects whose events you listen to.&amp;#160; The key is not to call &lt;em&gt;ReleaseCOMObject()&lt;/em&gt; on an item while you are still listening to events from it.&amp;#160; In the class below, notice that &lt;em&gt;_task&lt;/em&gt; is defined at the module level so that as long as the instance of &lt;em&gt;TaskRegion&lt;/em&gt; is alive and listening to the &lt;em&gt;Write()&lt;/em&gt; event &lt;em&gt;_task&lt;/em&gt; will not go out of scope and get garbage collected by the CLR.&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Timing&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;It seems like there is a general understanding now that Outlook objects need to be released.&amp;#160; Additionally, you must &lt;strong&gt;*always decrement the event handlers that you add*&lt;/strong&gt;.&amp;#160; However, the humor in a good joke is not just the punch line but also good timing – you have to be strategic about &lt;em&gt;when&lt;/em&gt; to call &lt;em&gt;ReleaseCOMObject() &lt;/em&gt;and &lt;em&gt;when&lt;/em&gt; to decrement the event handler.&amp;#160; Since this is a FormRegion class I’m utilizing the &lt;em&gt;FormRegionShowing&lt;/em&gt; event to initialize &lt;em&gt;_task&lt;/em&gt; and add the event handler and I use &lt;em&gt;FormRegionClosed&lt;/em&gt; to remove the event handler and release &lt;em&gt;_task&lt;/em&gt;.&amp;#160; In a simple item wrapper class you might use the constructor and a dispose method in the same way.&amp;#160; The goal is not call &lt;em&gt;ReleaseCOMObject()&lt;/em&gt; until the events are unhooked, that way the COM object become separated from your RCW that is still trying to handle events.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;…&lt;strong&gt;NOTE – &lt;/strong&gt;I’m also employing &lt;a href="http://blogs.msdn.com/pcreehan/archive/2008/08/07/form-region-leak-in-visual-studio-tools-for-office-2008-v3-template.aspx" target="_blank"&gt;Patrick’s fix&lt;/a&gt; in FormRegionInitializing for a FormRegion specific leak scenario…&lt;/em&gt;&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;partial class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TaskRegion
&lt;/span&gt;{
    Outlook.&lt;span style="color: #2b91af"&gt;TaskItem &lt;/span&gt;_task = &lt;span style="color: blue"&gt;null&lt;/span&gt;;

    &lt;span style="color: blue"&gt;#region &lt;/span&gt;Form Region Factory

    [Microsoft.Office.Tools.Outlook.&lt;span style="color: #2b91af"&gt;FormRegionMessageClass
        &lt;/span&gt;(Microsoft.Office.Tools.Outlook.&lt;span style="color: #2b91af"&gt;FormRegionMessageClassAttribute&lt;/span&gt;.Task)]
    [Microsoft.Office.Tools.Outlook.&lt;span style="color: #2b91af"&gt;FormRegionName
        &lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;ReleaseTaskRegion.TaskRegion&amp;quot;&lt;/span&gt;)]
    &lt;span style="color: blue"&gt;public partial class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TaskRegionFactory
    &lt;/span&gt;{
        &lt;span style="color: green"&gt;// Occurs before the form region is initialized.
        // To prevent the form region from appearing, set e.Cancel to true.
        // Use e.OutlookItem to get a reference to the current Outlook item.
        &lt;/span&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;TaskRegionFactory_FormRegionInitializing(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender,
            Microsoft.Office.Tools.Outlook.&lt;span style="color: #2b91af"&gt;FormRegionInitializingEventArgs &lt;/span&gt;e)
        {
            &lt;span style="color: #2b91af"&gt;Marshal&lt;/span&gt;.ReleaseComObject(e.OutlookItem);
        }
    }

    &lt;span style="color: blue"&gt;#endregion

    &lt;/span&gt;&lt;span style="color: green"&gt;// Occurs before the form region is displayed.
    // Use this.OutlookItem to get a reference to the current Outlook item.
    // Use this.OutlookFormRegion to get a reference to the form region.
    &lt;/span&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;TaskRegion_FormRegionShowing(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, System.&lt;span style="color: #2b91af"&gt;EventArgs &lt;/span&gt;e)
    {
        _task = &lt;span style="color: blue"&gt;this&lt;/span&gt;.OutlookItem &lt;span style="color: blue"&gt;as &lt;/span&gt;Outlook.&lt;span style="color: #2b91af"&gt;TaskItem&lt;/span&gt;;

        _task.Write += &lt;span style="color: blue"&gt;new &lt;/span&gt;Outlook.&lt;span style="color: #2b91af"&gt;ItemEvents_10_WriteEventHandler&lt;/span&gt;(_task_Write);
    }

    &lt;span style="color: blue"&gt;private void &lt;/span&gt;_task_Write(&lt;span style="color: blue"&gt;ref bool &lt;/span&gt;Cancel)
    {
        System.Diagnostics.&lt;span style="color: #2b91af"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;Write fired!&amp;quot;&lt;/span&gt;);
    }

    &lt;span style="color: green"&gt;// Occurs when the form region is closed.
    // Use this.OutlookItem to get a reference to the current Outlook item.
    // Use this.OutlookFormRegion to get a reference to the form region.
    &lt;/span&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;TaskRegion_FormRegionClosed(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, System.&lt;span style="color: #2b91af"&gt;EventArgs &lt;/span&gt;e)
    {
        _task.Write -= &lt;span style="color: blue"&gt;new &lt;/span&gt;Outlook.&lt;span style="color: #2b91af"&gt;ItemEvents_10_WriteEventHandler&lt;/span&gt;(_task_Write);

        System.Runtime.InteropServices.&lt;span style="color: #2b91af"&gt;Marshal&lt;/span&gt;.ReleaseComObject(_task);
    }
}&lt;/pre&gt;

&lt;p&gt;&lt;em&gt;…This post is a continuation of my efforts to document common issues I’ve seen when .NET programmers write solutions with Outlook’s object model – be they separate executables, VSTO Add-ins, or Outlook FormRegions. To see all the posts in this series check out my posts with the &lt;/em&gt;&lt;a href="http://blogs.msdn.com/&amp;hellip;This post is a continuation of my efforts to document common issues I&amp;rsquo;ve seen when .NET programmers write solutions with Outlook&amp;rsquo;s object model &amp;ndash; be they separate executables, VSTO Add-ins, or Outlook FormRegions.  To see all the posts in this series check out my posts with the OOM.NET tag&amp;hellip;"&gt;&lt;em&gt;OOM.NET&lt;/em&gt;&lt;/a&gt;&lt;em&gt; tag…&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;…To check out more blog posts from Microsoft’s Messaging Developer Support team which supports Outlook, Exchange, and other email-related development using Microsoft APIs check out the &lt;a href="http://blogs.msdn.com/search/Searchrss.aspx?tag=DevMsgTeam"&gt;DevMsgTeam&lt;/a&gt; tag across all MSDN blogs…&lt;/em&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9427731" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mstehle/archive/tags/Outlook+Object+Model/default.aspx">Outlook Object Model</category><category domain="http://blogs.msdn.com/mstehle/archive/tags/OOM.NET/default.aspx">OOM.NET</category><category domain="http://blogs.msdn.com/mstehle/archive/tags/DevMsgTeam/default.aspx">DevMsgTeam</category><category domain="http://blogs.msdn.com/mstehle/archive/tags/VSTO/default.aspx">VSTO</category></item><item><title>FYI: Want to build VSTO AddIns for Office 2007?  VSTO 2005 SE Download Available Now!</title><link>http://blogs.msdn.com/mstehle/archive/2006/11/06/fyi-want-to-build-vsto-addins-for-office-2007-vsto-2005-se-download-available-now.aspx</link><pubDate>Tue, 07 Nov 2006 00:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1004728</guid><dc:creator>mstehle</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/mstehle/comments/1004728.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mstehle/commentrss.aspx?PostID=1004728</wfw:commentRss><wfw:comment>http://blogs.msdn.com/mstehle/rsscomments.aspx?PostID=1004728</wfw:comment><description>&lt;P&gt;VSTO 2005 SE is a &lt;A class="" href="http://www.microsoft.com/downloads/details.aspx?FamilyId=5E86CAB3-6FD6-4955-B979-E1676DB6B3CB&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyId=5E86CAB3-6FD6-4955-B979-E1676DB6B3CB&amp;amp;displaylang=en"&gt;free&amp;nbsp;download&lt;/A&gt;&amp;nbsp;for&amp;nbsp;Visual Studio 2005 Tools for Office AND Visual Studio 2005 Professional that will allow you to build VSTO AddIns for Office 2007 applications.&lt;/P&gt;
&lt;P&gt;Note if you installed the CTP this summer...&lt;/P&gt;
&lt;P&gt;"&lt;STRONG&gt;VSTO “v3” CTP users:&lt;/STRONG&gt; If you previously installed any of the VSTO “v3” CTPs, you need to completely remove the CTP software from your computer before you install VSTO 2005 SE. Because the CTP’s ability to uninstall itself is very limited and unreliable, we strongly recommend that you restore your system in its entirety from a backup made before any VSTO “v3” CTP software was installed. This will require you to reinstall Visual Studio as well. If VSTO 2005 SE is installed on computers where VSTO “v3” CTP software is installed, or was installed but not removed properly, you may experience various error messages and failures. (If restoring a backup of your computer is not an option, you can try to uninstall Visual Studio 2005 and all related products from your computer, and then install them again. This is not guaranteed to completely remove the CTPs, but it has been reported to be sufficient to enable VSTO 2005 SE to work.) "&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1004728" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mstehle/archive/tags/Outlook+Object+Model/default.aspx">Outlook Object Model</category><category domain="http://blogs.msdn.com/mstehle/archive/tags/Outlook+General/default.aspx">Outlook General</category><category domain="http://blogs.msdn.com/mstehle/archive/tags/DevMsgTeam/default.aspx">DevMsgTeam</category><category domain="http://blogs.msdn.com/mstehle/archive/tags/VSTO/default.aspx">VSTO</category></item></channel></rss>