<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Dan's WebDAV 101</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/webdav_101/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/webdav_101/feed.xml</link>
    <description>This blog covers Messaging API development for Exchange and Outlook.  My name is Daniel Bagley, I&amp;#039;m on the Messaging Developer Team.</description>
    <lastBuildDate>Tue, 05 Mar 2019 18:36:21 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>No Supported Way to Deploy Outlook VBA Projects</title>
      <link>https://docs.microsoft.com/archive/blogs/webdav_101/no-supported-way-to-deploy-outlook-vba-projects</link>
      <pubDate>Tue, 05 Mar 2019 23:18:39 GMT</pubDate>
      <dc:creator><![CDATA[Webdav101]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/webdav_101/?p=3165</guid>
      <description><![CDATA[Distributing the VBA macro by replacing the VbaProject.OTM file on target Workstation is not...]]></description>
      <content:encoded><![CDATA[<p>Distributing the VBA macro by replacing the VbaProject.OTM file on target Workstation is not supported. The only supported way to share the Macro is to manually copy the code over to another machine. The couple of articles below allude the un-supportability of distributing VBA Macros:
</p><p style="margin-left: 36pt">No Supported Way to Deploy Outlook VBA Projects<br /><a href="http://blogs.msdn.com/b/mstehle/archive/2005/12/01/outbox-no-supported-way-to-deploy-outlook-vba-projects.aspx">http://blogs.msdn.com/b/mstehle/archive/2005/12/01/outbox-no-supported-way-to-deploy-outlook-vba-projects.aspx</a>
		<span style="font-family:Segoe UI;font-size:10pt">
		</span></p><p style="margin-left: 36pt">Using Visual Basic for Applications in Outlook<span style="text-decoration:underline"><br /><a href="https://msdn.microsoft.com/en-us/library/office/ff863909.aspx">https://msdn.microsoft.com/en-us/library/office/ff863909.aspx</a>
		</span>
		<span style="font-family:Segoe UI;font-size:10pt">
		</span></p><p><em>"Outlook Visual Basic for Applications code was designed to be a personal macro development environment, and was not designed to be deployed or distributed. To move a project from one computer to another, for example, moving the project from your work computer to your home computer, you can export the forms and code modules from the work computer and import them to the home computer. You can also copy and paste the source code of the project to Project1 on the home computer using the Visual Basic Editor. "</em><span style="font-family:Segoe UI;font-size:10pt">
		</span></p><p>When there is a need for Outlook enhancement for multiple users, our recommendation is to create an Outlook add-in for that purpose. It offers multiple features like customizing ribbon apart from using Outlook Object Model or MAPI (for a C++ add-in). I'm sharing additional info on building add-in in Outlook using Visual Studio
</p><ul style="margin-left: 72pt"><li>Walkthrough: Creating Your First Application-Level Add-in for Outlook <br />http://msdn.microsoft.com/en-us/library/cc668191.aspx
</li><li>Outlook Object Model Overview<br />http://msdn.microsoft.com/en-us/library/ms268893.aspx   
</li><li>Best Practices in Developing Managed Outlook Add-Ins<br />http://msdn.microsoft.com/en-us/library/office/bb611563(v=office.14).aspx    
</li><li>Extending the User Interface in Outlook 2010 <br />http://msdn.microsoft.com/en-us/library/ee692172.aspx#OfficeOLExtendingUI_Explorer
</li><li>Developing an Inspector Wrapper for Outlook 2010<br />http://msdn.microsoft.com/en-us/library/office/ff973716(v=office.14).aspx
</li><li>Deploying an Office Solution<br />https://msdn.microsoft.com/en-us/library/bb386179.aspx
</li></ul>]]></content:encoded>
    </item>
    <item>
      <title>Invoke-RestMethod : The underlying connection was closed:  An unexpected error occurred on a send. while using PowerShell</title>
      <link>https://docs.microsoft.com/archive/blogs/webdav_101/invoke-restmethod-the-underlying-connection-was-closed-an-unexpected-error-occurred-on-a-send-while-using-powershell</link>
      <pubDate>Thu, 28 Feb 2019 22:07:41 GMT</pubDate>
      <dc:creator><![CDATA[Webdav101]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/webdav_101/?p=3155</guid>
      <description><![CDATA[If you have gotten the "Invoke-RestMethod : The underlying connection was closed:  An unexpected...]]></description>
      <content:encoded><![CDATA[<p>
 </p><p>If you have gotten the "Invoke-RestMethod : The underlying connection was closed:  An unexpected error occurred on a send." error while using PowerShell then add the line below to your script.
</p><p>    ​[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 
</p><p>PowerShell calls uses TLS 1.0 for web requests by default.  However, Exchange is expecting a higher level of TLS, so you need to tell PowerShell to use 1.2 instead of the default of TLS 1.0.
</p><p>Below are links for additional information.
</p><p style="margin-left: 36pt"><a href="//blogs.technet.microsoft.com/exchange/2018/02/09/an-update-on-office-365-requiring-tls-1-2/">An Update on Office 365 Requiring TLS 1.2<br />https://blogs.technet.microsoft.com/exchange/2018/02/09/an-update-on-office-365-requiring-tls-1-2/</a>
	</p><p>    Preparing to use TLS 1.2 in Office 365<br />    <a href="https://support.microsoft.com/en-us/help/4057306/preparing-for-tls-1-2-in-office-365">https://support.microsoft.com/en-us/help/4057306/preparing-for-tls-1-2-in-office-365</a>
	</p><p>
 </p>]]></content:encoded>
    </item>
    <item>
      <title>The problem with modifying the iterating object in a “foreach”</title>
      <link>https://docs.microsoft.com/archive/blogs/webdav_101/the-problem-with-modifying-the-iterating-object-in-a-foreach</link>
      <pubDate>Fri, 15 Feb 2019 03:21:34 GMT</pubDate>
      <dc:creator><![CDATA[Webdav101]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/webdav_101/?p=3145</guid>
      <description><![CDATA[Matt Stehle used to be on my team prior and had blogged on the usage of Outlook Object Model (OOM)...]]></description>
      <content:encoded><![CDATA[<p><span style="color:#333333;font-family:Segoe UI;font-size:10pt;background-color:white">Matt Stehle used to be on my team prior and had blogged on the usage of Outlook Object Model (OOM) under .NET. However, his blog is being closed and I am re-blogging his content here.
</span></p><p style="background: white"><span style="color:#333333"><span style="font-family:Segoe UI"><span style="font-size:10pt">
				</span><span style="font-size:10pt">Ahhh "foreach". Usage of foreach can be either a blessing or a curse. Unfortunately, a lot of developers don't understand that it can cause issues. The need to avoid it when code in a foreach will do an operation (move, delete, etc.) is something which blows the minds of even seasoned developers.<br /></span></span><span style="font-family:Times New Roman;font-size:10pt">
			</span></span></p><p style="background: white"><span style="color:#333333"><span style="font-family:Segoe UI;font-size:10pt">What you will see happen when an operation like a delete or move is done on the iterating item is that the position of where the underlying code is in the collection will be thrown off and the next item to be processed will be skipped. This can/will cause items to not get processed and can otherwise introduce leaks into your application. This isn't limited to working with .NET, OOM or when COM objects are used – it happens for all types of code.<br /></span><span style="font-family:Times New Roman;font-size:10pt">
			</span></span></p><p style="background: white"><span style="color:#333333"><span style="font-family:Segoe UI;font-size:10pt">To work around this, you should look at using a reverse for-each loop on the index of the item in the collection instead. Yes, sometimes the best way to do things is backwards.</span><span style="font-family:Times New Roman;font-size:10pt">
			</span></span></p><p>
 </p><p><span style="color:#333333;font-family:Segoe UI;font-size:10pt;background-color:white">
		</span> </p>]]></content:encoded>
    </item>
    <item>
      <title>OOM.NET - Outlook Crashes When Using Outlook Object Model in Multiple Threads</title>
      <link>https://docs.microsoft.com/archive/blogs/webdav_101/oom-net-outlook-crashes-when-using-outlook-object-model-in-multiple-threads</link>
      <pubDate>Fri, 15 Feb 2019 03:19:12 GMT</pubDate>
      <dc:creator><![CDATA[Webdav101]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/webdav_101/?p=3135</guid>
      <description><![CDATA[Matt Stehle used to be on my team prior and had blogged on the usage of Outlook Object Model (OOM)...]]></description>
      <content:encoded><![CDATA[<span style="color: #333333;font-family: Segoe UI;font-size: 10pt;background-color: white">Matt Stehle used to be on my team prior and had blogged on the usage of Outlook Object Model (OOM) under .NET. However, his blog is being closed and I am re-blogging his content here.
</span>

<span style="color: #333333;font-family: Times New Roman;font-size: 10pt">One of the major requirements most developers are up against these days is ensuring their code runs as fast as possible. No one likes to wait for an application to run, they want seamless, invisible, instant speed. Multithreading is becoming more popular now that many desktops and certainly most servers are shipping with multiple processors or multiple cores. By spinning up multiple threads to execute many different code-paths simultaneously, you can certainly increase the performance of your application.
</span>

<span style="color: #333333;font-family: Times New Roman;font-size: 10pt">This mentality is ever-increasingly being blended into Outlook development as well. There has been a rash of developers in recent months who are reporting problems with their Outlook add-ins crashing Outlook when doing multi-threading. While it may give the perception of a better performing add-in, the reality is that this really isn't going to help, nor will it work.
</span>

<span style="color: #333333;font-family: Times New Roman;font-size: 10pt">Outlook Object Model is run in a <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/ms680112.aspx" rel="noopener">STA</a> COM server. This means that all OOM calls are executed on the main thread. If you are building an add-in that is making OOM calls from another thread (other than the main thread), then your calls need to be properly marshaled back to thread 0. For unmanaged code, you should use <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/ms678428(VS.85).aspx" rel="noopener">CoMarshalInterface</a> or <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/ms693316(VS.85).aspx" rel="noopener">CoMarshalInterThreadInterfaceInStream</a> to marshal your object pointer across threads. This will ensure your OOM calls are properly executed on thread 0. If you are writing managed code, using the OOM through COM interop by means of the PIA will actually handle this marshalling for you.
</span>

<span style="color: #333333;font-family: Times New Roman;font-size: 10pt">All of this talk about marshalling interfaces back to the main thread begs the question, "What's the point?" If the OOM calls need to run on thread 0, why spin up a new thread to do OOM work in the first place? That's a great question. You don't gain any performance because all the calls are going to run on the same thread anyway <em>and</em> you incur the overhead hit of doing the marshaling to begin with, so there's not really an advantage to multithreading Outlook Object Model.
</span>

<span style="color: #333333;font-family: Times New Roman;font-size: 10pt">Here are some links to some smart folks talking about this same thing:
</span>
<p style="margin-left: 36pt"><a target="_blank" href="http://weblogs.asp.net/whaggard/archive/2008/02/04/all-outlook-object-model-calls-run-on-the-main-thread.aspx" rel="noopener" title="http://weblogs.asp.net/whaggard/archive/2008/02/04/all-outlook-object-model-calls-run-on-the-main-thread.aspx"><span style="font-family: Times New Roman;font-size: 10pt">All Outlook object model calls run on the main thread</span></a><span style="color: #333333;font-family: Times New Roman;font-size: 10pt">
</span></p>
<p style="margin-left: 36pt"><a target="_blank" href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1858663&amp;SiteID=1" rel="noopener" title="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1858663&amp;SiteID=1"><span style="font-family: Times New Roman;font-size: 10pt">Threading in an Outlook Addin</span></a><span style="color: #333333;font-family: Times New Roman;font-size: 10pt">
</span></p>
<p style="margin-left: 36pt"><a target="_blank" href="http://www.outlookcode.com/article.aspx?id=71" rel="noopener" title="Add-in threading issue causes Outlook to crash or hang"><span style="font-family: Times New Roman;font-size: 10pt">Add-in threading issue causes Outlook to crash or hang</span></a><span style="color: #333333;font-family: Times New Roman;font-size: 10pt">
</span></p>
Dan's

<a href="https://blogs.msdn.microsoft.com/webdav_101/2016/07/27/oom-net-the-problem-with-modifying-the-iterating-object-in-a-foreach/">https://blogs.msdn.microsoft.com/webdav_101/2016/07/27/oom-net-the-problem-with-modifying-the-iterating-object-in-a-foreach/</a>]]></content:encoded>
    </item>
    <item>
      <title>OOM.NET - Like a good standup comic – use scope and have good timing…</title>
      <link>https://docs.microsoft.com/archive/blogs/webdav_101/oom-net-like-a-good-standup-comic-use-scope-and-have-good-timing</link>
      <pubDate>Fri, 15 Feb 2019 03:17:04 GMT</pubDate>
      <dc:creator><![CDATA[Webdav101]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/webdav_101/?p=3125</guid>
      <description><![CDATA[Matt Stehle used to be on my team prior and had blogged on the usage of Outlook Object Model (OOM)...]]></description>
      <content:encoded><![CDATA[<span style="color: #333333;font-family: Segoe UI;font-size: 10pt;background-color: white">Matt Stehle used to be on my team prior and had blogged on the usage of Outlook Object Model (OOM) under .NET. However, his blog is being closed and I am re-blogging his content here.
</span>

<span style="color: #333333;font-family: Times New Roman;font-size: 10pt">Recently, I was helping someone with a Outlook item leak type issue involving a Task FormRegion.  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."  They were familiar with some of the issues discussed here and knew to call <em>ReleaseCOMObject()</em> on objects as they were done with them.  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.  The following class is a simple example of that scope and timing…
</span>

<span style="color: #333333;font-family: Times New Roman;font-size: 10pt"><strong>Scope</strong>
</span>

<span style="color: #333333;font-family: Times New Roman;font-size: 10pt">As I pointed out in <a target="_blank" href="http://blogs.msdn.com/mstehle/archive/2007/12/06/oom-net-part-1-introduction-why-events-stop-firing.aspx" rel="noopener">my original OOM.NET post</a>, you need to consider the scope of the objects whose events you listen to.  The key is not to call <em>ReleaseCOMObject()</em> on an item while you are still listening to events from it.  In the class below, notice that <em>_task</em> is defined at the module level so that as long as the instance of <em>TaskRegion</em> is alive and listening to the <em>Write()</em> event <em>_task</em> will not go out of scope and get garbage collected by the CLR.
</span>

<span style="color: #333333;font-family: Times New Roman;font-size: 10pt"><strong>Timing</strong>
</span>

<span style="color: #333333;font-family: Times New Roman;font-size: 10pt">It seems like there is a general understanding now that Outlook objects need to be released.  Additionally, you must <strong>*always decrement the event handlers that you add*</strong>.  However, the humor in a good joke is not just the punch line but also good timing – you have to be strategic about <em>when</em> to call <em>ReleaseCOMObject() </em>and <em>when</em> to decrement the event handler.  Since this is a FormRegion class I'm utilizing the <em>FormRegionShowing</em> event to initialize <em>_task</em> and add the event handler and I use <em>FormRegionClosed</em> to remove the event handler and release <em>_task</em>.  In a simple item wrapper class you might use the constructor and a dispose method in the same way.  The goal is not call <em>ReleaseCOMObject()</em> until the events are unhooked, that way the COM object become separated from your RCW that is still trying to handle events.
</span>

<span style="color: #333333;font-family: Times New Roman;font-size: 10pt"><em>…<strong>NOTE – </strong>I'm also employing <a target="_blank" href="http://blogs.msdn.com/pcreehan/archive/2008/08/07/form-region-leak-in-visual-studio-tools-for-office-2008-v3-template.aspx" rel="noopener">Patrick's fix</a> in FormRegionInitializing for a FormRegion specific leak scenario…</em>
</span>
<pre><code><span style="color: blue;font-family: Consolas">partial class <span style="color: #2b91af">TaskRegion
</span></span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">{
</span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">    Outlook.<span style="color: #2b91af">TaskItem <span style="color: #333333">_task = <span style="color: blue">null<span style="color: #333333">;
</span></span></span></span></span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">
					<span style="color: blue">#region <span style="color: #333333">Form Region Factory
</span></span></span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">    [Microsoft.Office.Tools.Outlook.<span style="color: #2b91af">FormRegionMessageClass
</span></span></code></pre>
<pre><code><span style="color: #2b91af;font-family: Consolas">
					<span style="color: #333333">(Microsoft.Office.Tools.Outlook.<span style="color: #2b91af">FormRegionMessageClassAttribute<span style="color: #333333">.Task)]
</span></span></span></span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">    [Microsoft.Office.Tools.Outlook.<span style="color: #2b91af">FormRegionName
</span></span></code></pre>
<pre><code><span style="color: #2b91af;font-family: Consolas">
					<span style="color: #333333">(<span style="color: #a31515">"ReleaseTaskRegion.TaskRegion"<span style="color: #333333">)]
</span></span></span></span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">
					<span style="color: blue">public partial class <span style="color: #2b91af">TaskRegionFactory
</span></span></span></code></pre>
<pre><code><span style="color: #2b91af;font-family: Consolas">
					<span style="color: #333333">{
</span></span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">
					<span style="color: green">// Occurs before the form region is initialized.
</span></span></code></pre>
<pre><code><span style="color: green;font-family: Consolas">        // To prevent the form region from appearing, set e.Cancel to true.
</span></code></pre>
<pre><code><span style="color: green;font-family: Consolas">        // Use e.OutlookItem to get a reference to the current Outlook item.
</span></code></pre>
<pre><code><span style="color: green;font-family: Consolas">
					<span style="color: blue">private void <span style="color: #333333">TaskRegionFactory_FormRegionInitializing(<span style="color: blue">object <span style="color: #333333">sender,
</span></span></span></span></span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">            Microsoft.Office.Tools.Outlook.<span style="color: #2b91af">FormRegionInitializingEventArgs <span style="color: #333333">e)
</span></span></span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">        {
</span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">
					<span style="color: #2b91af">Marshal<span style="color: #333333">.ReleaseComObject(e.OutlookItem);
</span></span></span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">        }
</span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">    }
</span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">
					<span style="color: blue">#endregion
</span></span></code></pre>
<pre><code><span style="color: blue;font-family: Consolas">
					<span style="color: green">// Occurs before the form region is displayed.
</span></span></code></pre>
<pre><code><span style="color: green;font-family: Consolas">    // Use this.OutlookItem to get a reference to the current Outlook item.
</span></code></pre>
<pre><code><span style="color: green;font-family: Consolas">    // Use this.OutlookFormRegion to get a reference to the form region.
</span></code></pre>
<pre><code><span style="color: green;font-family: Consolas">
					<span style="color: blue">private void <span style="color: #333333">TaskRegion_FormRegionShowing(<span style="color: blue">object <span style="color: #333333">sender, System.<span style="color: #2b91af">EventArgs <span style="color: #333333">e)
</span></span></span></span></span></span></span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">    {
</span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">        _task = <span style="color: blue">this<span style="color: #333333">.OutlookItem <span style="color: blue">as <span style="color: #333333">Outlook.<span style="color: #2b91af">TaskItem<span style="color: #333333">;
</span></span></span></span></span></span></span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">        _task.Write += <span style="color: blue">new <span style="color: #333333">Outlook.<span style="color: #2b91af">ItemEvents_10_WriteEventHandler<span style="color: #333333">(_task_Write);
</span></span></span></span></span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">    }
</span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">
					<span style="color: blue">private void <span style="color: #333333">_task_Write(<span style="color: blue">ref bool <span style="color: #333333">Cancel)
</span></span></span></span></span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">    {
</span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">        System.Diagnostics.<span style="color: #2b91af">Debug<span style="color: #333333">.WriteLine(<span style="color: #a31515">"Write fired!"<span style="color: #333333">);
</span></span></span></span></span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">    }
</span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">
					<span style="color: green">// Occurs when the form region is closed.
</span></span></code></pre>
<pre><code><span style="color: green;font-family: Consolas">    // Use this.OutlookItem to get a reference to the current Outlook item.
</span></code></pre>
<pre><code><span style="color: green;font-family: Consolas">    // Use this.OutlookFormRegion to get a reference to the form region.
</span></code></pre>
<pre><code><span style="color: green;font-family: Consolas">
					<span style="color: blue">private void <span style="color: #333333">TaskRegion_FormRegionClosed(<span style="color: blue">object <span style="color: #333333">sender, System.<span style="color: #2b91af">EventArgs <span style="color: #333333">e)
</span></span></span></span></span></span></span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">    {
</span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">        _task.Write -= <span style="color: blue">new <span style="color: #333333">Outlook.<span style="color: #2b91af">ItemEvents_10_WriteEventHandler<span style="color: #333333">(_task_Write);
</span></span></span></span></span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">        System.Runtime.InteropServices.<span style="color: #2b91af">Marshal<span style="color: #333333">.ReleaseComObject(_task);
</span></span></span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">    }
</span></code></pre>
<pre><code><span style="color: #333333;font-family: Consolas">}
</span></code></pre>
<span style="color: #333333;font-family: Times New Roman;font-size: 10pt"><em>…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 <a href="http://blogs.msdn.com/…This%20post%20is%20a%20continuation%20of%20my%20efforts%20to%20document%20common%20issues%20I’ve%20seen%20when%20.NET%20programmers%20write%20solutions%20with%20Outlook’s%20object%20model%20–%20be%20they%20separate%20executables,%20VSTO%20Add-ins,%20or%20Outlook%20FormRegions.%20%20To%20see%20all%20the%20posts%20in%20this%20series%20check%20out%20my%20posts%20with%20the%20OOM.NET%20tag…"><span style="color: #337ab7">OOM.NET</span></a> tag…</em>
</span>

<span style="color: #333333;font-family: Times New Roman;font-size: 10pt"><em>…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 <a href="http://blogs.msdn.com/search/Searchrss.aspx?tag=DevMsgTeam">DevMsgTeam</a> tag across all MSDN blogs…</em>
</span>

PcREEHAN'S Articles:

<a href="http://blogs.msdn.com/pcreehan/archive/2008/03/13/outlook-crashes-when-using-outlook-object-model-in-multiple-threads.aspx">http://blogs.msdn.com/pcreehan/archive/2008/03/13/outlook-crashes-when-using-outlook-object-model-in-multiple-threads.aspx</a>]]></content:encoded>
    </item>
    <item>
      <title>OOM.NET Part 4 – Don’t Thread On Me</title>
      <link>https://docs.microsoft.com/archive/blogs/webdav_101/oom-net-part-4-dont-thread-on-me</link>
      <pubDate>Fri, 15 Feb 2019 03:13:00 GMT</pubDate>
      <dc:creator><![CDATA[Webdav101]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/webdav_101/?p=3115</guid>
      <description><![CDATA[Matt Stehle used to be on my team prior and had blogged on the usage of Outlook Object Model (OOM)...]]></description>
      <content:encoded><![CDATA[Matt Stehle used to be on my team prior and had blogged on the usage of Outlook Object Model (OOM) under .NET. However, his blog is being closed and I am re-blogging his content here.

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">Patrick posted a discussion of multithreading with Outlook Object Model and why it <strong>doesn't</strong> help to make OOM calls on a separate thread...</span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt"><em>"Outlook Object Model is run in a <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/ms680112.aspx" rel="noopener"><span style="color: #337ab7">STA</span></a> COM server. This means that all OOM calls are executed on the main thread...You don't gain any performance [when multithreading] because all the calls are going to run on the same thread anyway and you incur the overhead hit of doing the marshaling to begin with, so there's not really an advantage to multithreading Outlook Object Model."</em></span><span style="font-family: Times New Roman;font-size: 13pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">The typical scenario is a VSTO or .NET Shared AddIn for Outlook that wants to do some kind of "background" processing of items in a separate thread as to not hold up the UI.  This other thread will have OOM code in it that loops through items, folders, or both.  This is the kind of thread that actually <strong>hurts</strong> performance - using OOM on a separate thread rather than the main thread.  If an AddIn makes use of separate threads for working with things outside Outlook such as a database, filesystem, etc. then these recommendations don't apply necessarily.</span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">Creating new threads and even marshalling between them is pretty easy in .NET and like many things in .NET (and VB6 before it) is that this marshalling and threading is supposed to "just work".  Developers can get a lot of this working without really <strong>understanding</strong> what is going on and what is required to make this work.  An understanding of COM and what it means to STA like Outlook Object Model is required to come to the conclusions in Patrick's post.</span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>]]></content:encoded>
    </item>
    <item>
      <title>Part 3 – Back to the Basics, MSDN Must Reads</title>
      <link>https://docs.microsoft.com/archive/blogs/webdav_101/part-3-back-to-the-basics-msdn-must-reads</link>
      <pubDate>Fri, 15 Feb 2019 03:07:15 GMT</pubDate>
      <dc:creator><![CDATA[Webdav101]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/webdav_101/?p=3105</guid>
      <description><![CDATA[Matt Stehle used to be on my team prior and had blogged on the usage of Outlook Object Model (OOM)...]]></description>
      <content:encoded><![CDATA[Matt Stehle used to be on my team prior and had blogged on the usage of Outlook Object Model (OOM) under .NET. However, his blog is being closed and I am re-blogging his content here.

<span style="color: #333333;font-family: Times New Roman"><span style="font-size: 10pt">The Outlook Developer Reference on MSDN has great information on .NET and COM interop which I would consider a prerequisite to any managed code development with Outlook Object Model.  It simply isn't enough to know how to accomplish tasks with OOM or to call GC.Collect here and there - it is important to understand the whole story...</span><span style="font-size: 10pt">
</span></span>

<a href="http://msdn2.microsoft.com/en-us/library/bb610378.aspx"><span style="font-family: Times New Roman;font-size: 10pt">Introduction to Interoperability Between COM and .NET</span></a><span style="color: #333333;font-family: Times New Roman"><span style="font-size: 10pt"> - This is a short and sweet run through of COM Interop and sets up a foundation for understanding where some of the issues come from in my previous posts (OOM.NET <a href="http://blogs.msdn.com/mstehle/archive/2007/12/06/oom-net-part-1-introduction-why-events-stop-firing.aspx">Part 1</a> &amp; <a href="http://blogs.msdn.com/mstehle/archive/2007/12/07/oom-net-part-2-outlook-item-leaks.aspx">Part 2</a>).  Be sure to pay attention to the following quote...</span><span style="font-size: 10pt">
</span></span>
<p style="margin-left: 36pt"><span style="color: #333333;font-family: Times New Roman"><span style="font-size: 10pt">"...a COM client manages an internal reference count provided by <a href="http://go.microsoft.com/fwlink/?LinkId=88442">IUnknown</a> to free a coclass, a .NET client relies on the runtime garbage collector provided by the .NET platform to free an object..."</span><span style="font-size: 13pt">
</span></span></p>
<p style="margin-left: 36pt"><span style="color: #333333;font-family: Times New Roman"><span style="font-size: 10pt">...That is why <a href="http://msdn2.microsoft.com/en-us/library/system.runtime.interopservices.marshal.releasecomobject.aspx">RelaseCOMObject</a> is so important - in the Outlook world of item in reuse we cannot rely on the runtime garbage collector provided by the .NET platform to free an object.</span><span style="font-size: 10pt">
</span></span></p>
<span style="color: #333333;font-family: Times New Roman"><span style="font-size: 10pt">There is also some 101 type information about what a PIA is found in <a href="http://msdn2.microsoft.com/en-us/library/bb645534.aspx">Why Use the Outlook PIA</a> - the take away from this is, "Any number of interop assemblies can exist to describe a given COM type. As publisher of the type library, Outlook provides a Primary Interop Assembly (PIA) that contains the official description of the COM-based Outlook object model."  <a href="http://msdn2.microsoft.com/en-us/library/bb646840.aspx">Installing and Referencing the Outlook 2007 PIA</a> takes the next step to show how to add the reference in Visual Studio.  The list of classes and interfaces in OOM as seen by VB6 or VBA differ greatly from what is seen in a .NET project - for an explanation of that phenomenon read, <a href="http://msdn2.microsoft.com/en-us/library/bb609695.aspx">Relating the Outlook PIA with the Object Model</a>.</span><span style="font-size: 10pt">
</span></span>

<span style="color: #333333;font-family: Times New Roman"><span style="font-size: 10pt">The MSDN documentation hits on some of the points I made in <a href="https://blogs.msdn.microsoft.com/webdav_101/2019/02/15/oom-net-part-1-introduction-and-why-events-stop-firing/">Part 1</a> and <a href="https://blogs.msdn.microsoft.com/webdav_101/2019/02/15/oom-net-part-2-outlook-item-leaks/">Part 2</a> of OOM.NET:</span><span style="font-size: 10pt">
</span></span>
<p style="margin-left: 18pt"><a href="http://msdn2.microsoft.com/en-us/library/bb646475.aspx"><span style="font-family: Times New Roman;font-size: 10pt">Scoping Variables Appropriately in Event Handlers</span></a></p>
<p style="margin-left: 18pt"><a href="http://msdn2.microsoft.com/en-us/library/bb623945.aspx"><span style="font-family: Times New Roman;font-size: 10pt">Systematically Releasing Objects</span></a><span style="color: #333333;font-family: Times New Roman;font-size: 10pt">
</span></p>
<span style="color: #333333;font-family: Times New Roman;font-size: 10pt"><em>Looking forward to Part 4 of OOM.NET...</em>
</span>
<p style="margin-left: 36pt"><span style="color: #333333;font-family: Times New Roman;font-size: 10pt"><em>A <strong>huge</strong> area of trouble is in the handling of events and how to structure code and understand the code in the PIA to prevent item leaks.  I'll be posting more information on this topic soon - in the meantime read the following two articles for some background information...</em>
</span></p>
<p style="margin-left: 72pt"><a href="http://msdn2.microsoft.com/en-us/library/bb610520.aspx"><span style="color: #337ab7;font-family: Times New Roman;font-size: 10pt"><em>Connecting to Custom Event Handlers</em></span></a><span style="color: #333333;font-family: Times New Roman;font-size: 10pt">
</span></p>
<p style="margin-left: 72pt"><a href="http://msdn2.microsoft.com/en-us/library/bb644571.aspx"><span style="color: #337ab7;font-family: Times New Roman;font-size: 10pt"><em>Events in the Outlook PIA</em></span></a><span style="color: #333333;font-family: Times New Roman;font-size: 10pt">
</span></p>]]></content:encoded>
    </item>
    <item>
      <title>OOM.NET Part 2 – Outlook Item Leaks</title>
      <link>https://docs.microsoft.com/archive/blogs/webdav_101/oom-net-part-2-outlook-item-leaks</link>
      <pubDate>Fri, 15 Feb 2019 02:57:00 GMT</pubDate>
      <dc:creator><![CDATA[Webdav101]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/webdav_101/?p=3095</guid>
      <description><![CDATA[Matt Stehle used to be on my team prior and had blogged on the usage of Outlook Object Model (OOM)...]]></description>
      <content:encoded><![CDATA[Matt Stehle used to be on my team prior and had blogged on the usage of Outlook Object Model (OOM) under .NET. However, his blog is being closed and I am re-blogging his content here.
<p style="background: white"><span style="color: #333333;font-family: Segoe UI;font-size: 10pt">Outlook item leaks are the most common OOM with .NET issues that we see and I've debugged enough of them to compile this list of the four basic mistakes that contribute to item leaks. An "item leak" is most commonly seen as an item that won't refresh or can't be saved in the Outlook UI. A common example of this problem is that a user will complain that they receive a dialog stating that they can't save or update an appointment in Outlook when a particular AddIn is loaded. This is because the AddIn has not released the item reference and Outlook is reusing it. In order to fix the problem properly you need to look at your code for a few of the common mistakes listed below…
</span></p>
<p style="background: white"><span style="color: #333333;font-family: Segoe UI;font-size: 10pt"><strong>Outlook Processes Reuse Cached Item References</strong>
</span></p>
<p style="background: white"><span style="color: #333333;font-family: Segoe UI;font-size: 10pt">
If an item is in memory in Outlook.EXE then Outlook will reuse it when another action requests it. For example, if a COM AddIn leaks an item reference and a user is interacting with that item through the UI they might not be able to save their changes all of a sudden. This is especially true if the item were to be modified in the MAPI store after it has been leaked. An easy test would be to modify the suspected leaked item using MFCMAPI while Outlook is running then open the item in the Outlook UI and try to modify it. You will get a dialog saying that the item cannot be saved if you have leaked the item.
</span></p>
<p style="background: white"><span style="color: #333333;font-family: Segoe UI;font-size: 10pt"><strong>Do Not Chain Child Object References</strong>
</span></p>
<p style="background: white"><span style="color: #333333;font-family: Segoe UI;font-size: 10pt">One of the advantages of pure .NET programming is that you don't have to worry about memory management because the garbage collector and the dispose pattern handle all of that. What we have to remember that OOM programming in .NET is not pure .NET programming ***it is COM programming in .NET*** because of that the rules of COM apply here. Every object referenced must be released. When you chain objects you lose track of a reference that you need to release.
</span></p>
<p style="background: white"><span style="color: #333333;font-family: Segoe UI;font-size: 10pt">See the example below...
</span></p>
<p style="background: white;margin-left: 22pt"><span style="color: green"><span style="font-family: Arial;font-size: 10pt">// This leaks an Attachments reference</span><span style="color: #333333"><span style="font-family: Segoe UI;font-size: 10pt">
</span><span style="font-family: Arial;font-size: 10pt">ProcessAttachments(email.Attachments);</span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></span></p>
<p style="background: white;margin-left: 22pt"><span style="color: green"><span style="font-family: Arial;font-size: 10pt">// This doesn't leak</span><span style="color: #333333"><span style="font-family: Segoe UI;font-size: 10pt">
</span><span style="font-family: Arial;font-size: 10pt">Outlook.Attachments oAttachs = email.Attachments;</span><span style="font-family: Segoe UI;font-size: 10pt">
</span><span style="font-family: Arial;font-size: 10pt">ProcessAttachments(oAttachs);</span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></span></p>
<p style="background: white;margin-left: 22pt"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">Marshal.ReleaseCOMObject(oAttachs);</span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333;font-family: Segoe UI;font-size: 10pt"> oAttachs = <span style="color: blue">null<span style="color: #333333">;
</span></span></span></p>
<p style="background: white"><span style="color: #333333;font-family: Segoe UI;font-size: 10pt">Since the reference to the Attachments object is maintained it can be released properly.
</span></p>
<p style="background: white"><span style="color: #333333;font-family: Segoe UI;font-size: 10pt"><strong>Leaking a Child Item Leaks the Parent</strong>
</span></p>
<p style="background: white"><span style="color: #333333;font-family: Segoe UI;font-size: 10pt">If a child item that holds an internal reference to its parent – such as attachments or recipients - is leaked then the parent is in turn leaked. In the example above, chaining and leaking the child Attachments collection of the email will cause the email itself to leak. The parent object will never get cleaned up regardless of how many times GC.Collect or ReleaseCOMObject are called.
</span></p>
<p style="background: white"><span style="color: #333333;font-family: Segoe UI;font-size: 10pt"><strong>Be Careful with <em>foreach</em> Loops</strong>
</span></p>
<p style="background: white"><span style="color: #333333;font-family: Segoe UI;font-size: 10pt">The basic use of a foreach loop to iterate through items in a collection that have an internal reference to their parent – see above - will leak items. Either avoid foreach loops altogether by using for loops...
</span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">
<span style="color: green">// This leaks, GC.Collect will not help</span></span><span style="color: #333333;font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">
<span style="color: blue">foreach<span style="color: #333333"> (Outlook.Attachment oAttach <span style="color: blue">in<span style="color: #333333"> oAttachs)</span></span></span></span></span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt"> {</span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt"> Marshal.ReleaseCOMObject(oAttach);</span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt"> oAttach = <span style="color: blue">null<span style="color: #333333">;</span></span></span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt"> }</span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">
<span style="color: green">// This doesn't leak</span></span><span style="color: #333333;font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: green"><span style="font-family: Arial;font-size: 10pt">        <span style="color: blue;text-decoration: line-through">for<span style="color: black"> (<span style="color: blue">int<span style="color: black"> i = 1; i &lt; oAttachs.Count; i++) </span></span></span></span></span><span style="color: #333333;font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">
<span style="color: blue">for<span style="color: #333333"> (<span style="color: blue">int<span style="color: #333333"> i = 1; i =&lt; oAttachs.Count; i++)</span></span></span></span></span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt"> {</span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt"> Outlook.Attachment oAttach = oAttachs[i];</span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">
<span style="color: green">// Do nothing with attachment</span></span><span style="color: #333333;font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt"> Marshal.ReleaseCOMObject(oAttach);</span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt"> oAttach = <span style="color: blue">null<span style="color: #333333">;</span></span></span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt"> }</span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">…or follow the notes in <a href="http://discuss.develop.com/archives/wa.exe?A2=ind0204C&amp;L=DOTNET&amp;P=68505"><span style="color: blue">this discussion</span></a> to articulate the handling and cleanup of the underlying objects in the enumerator created by the foreach loop to ensure that things get cleaned up properly…</span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">
<span style="color: #2b91af">IEnumerator<span style="color: #333333"> attachsEnum = oAttaches.GetEnumerator();</span></span></span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">
<span style="color: blue">while<span style="color: #333333"> (attachsEnum.MoveNext())</span></span></span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt"> {</span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt"> Attachment at = (Attachment)attachsEnum.Current;</span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt"> Marshal.ReleaseCOMObject(at);</span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt"> }</span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt"> ICustomAdapter adapter = (ICustomAdapter)attachsEnum;</span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt"> Marshal.ReleaseComObject(adapter.GetUnderlyingObject());</span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>
<p style="background: white"><span style="color: #333333"><span style="font-family: Arial;font-size: 10pt"> Marshal.ReleaseComObject(oAttaches);</span><span style="font-family: Segoe UI;font-size: 10pt">
</span></span></p>]]></content:encoded>
    </item>
    <item>
      <title>OOM.NET Part 1 – Introduction and Why Events Stop Firing…</title>
      <link>https://docs.microsoft.com/archive/blogs/webdav_101/oom-net-part-1-introduction-and-why-events-stop-firing</link>
      <pubDate>Fri, 15 Feb 2019 02:51:31 GMT</pubDate>
      <dc:creator><![CDATA[Webdav101]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/webdav_101/?p=3085</guid>
      <description><![CDATA[Matt Stehle used to be on my team prior and had blogged on the usage of Outlook Object Model (OOM)...]]></description>
      <content:encoded><![CDATA[Matt Stehle used to be on my team prior and had blogged on the usage of Outlook Object Model (OOM) under .NET. However, his blog is being closed and I am re-blogging his content here.

<span style="color: #333333;font-family: Times New Roman"><span style="font-size: 10pt"><em>OOM.NET is not a special API set that was created in managed code.  It is the name I've given to a series of posts I'll do about the "gotchas" of Outlook Object Model development in .NET.  I've compiled some notes over time of the most common issues, how to resolve them, and why they exist.  I'd love to hear back from you on other issues you face with OOM programming in .NET as well so that I can add them to this series...</em></span><span style="font-size: 10pt">
</span></span>

<span style="color: #333333;font-family: Times New Roman"><span style="font-size: 10pt">With the introduction of Visual Studio Tools for Office and the maturity of .NET languages in general more and more Outlook developers are using .NET languages like C# and VB.NET.  The nice thing about .NET is that it encapsulates a lot of common functionality into a framework, manages memory, provides a framework for inter-operating with COM, and allows you to quickly write applications with very little concern for how all this happens.</span><span style="font-size: 10pt">
</span></span>
<p style="margin-left: 36pt"><span style="color: #333333;font-family: Times New Roman"><span style="font-size: 10pt"><strong>The bad thing about .NET is that it allows you to quickly write applications with very little concern for how all that happens...</strong></span><span style="font-size: 10pt">
</span></span></p>
<span style="color: #333333;font-family: Times New Roman"><span style="font-size: 10pt">Developers can get caught up in the ease and speed of development in .NET.  They can suffer from an "It Just Works Addiction" - meaning in the bliss of swiftly writing code that just happens to compile and run it is possible to lose sight of what is making everything work.  This mentality simply will not work with Outlook development; especially in .NET because there is just too much that can happen to adversely affect your application.  So on with the show... </span><span style="font-size: 10pt">
</span></span>

<span style="color: #333333;font-family: Times New Roman"><span style="font-size: 10pt"><strong>Why Events Stop Firing </strong></span><span style="font-size: 10pt">
</span></span>

<span style="color: #333333;font-family: Times New Roman"><span style="font-size: 10pt">Typically, the events stop firing problems come from adding an event handler from a locally scoped object or calling ReleaseCOMObject on an object which you are listening to events on.  The code below will eventually stop handling the NewInspector event because <em>inspectors</em> is locally scoped here and when GC runs it will get cleaned up thus stopping the event to fire… </span><span style="font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">        <span style="color: blue">private<span style="color: #333333">
<span style="color: blue">void<span style="color: #333333"> ThisAddIn_Startup(<span style="color: blue">object<span style="color: #333333"> sender, <span style="color: #2b91af">EventArgs<span style="color: #333333"> e) </span></span></span></span></span></span></span></span></span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">        { </span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">            Outlook.<span style="color: #2b91af">Inspectors<span style="color: #333333"> inspectors; </span></span></span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">            inspectors = Application.Inspectors; </span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">            inspectors.NewInspector += Inspectors_NewInspector; </span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333;font-family: Times New Roman"><span style="font-size: 10pt">        } </span><span style="font-size: 10pt">
</span></span>

<span style="color: #333333;font-family: Times New Roman"><span style="font-size: 10pt">To fix it you would need to make <em>inspectors</em> a module level variable and call <em>ReleaseCOMObject</em> within a dispose method or in this case inside <em>ThisAddIn_Shutdown</em>.  You wouldn't want to call <em>ReleaseCOMObject</em> on <em>inspectors</em> within <em>ThisAddIn_Startup</em> because it would free the underlying COM object and also cause your event to stop firing. </span><span style="font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">        <span style="color: blue">private<span style="color: #333333"> Outlook.<span style="color: #2b91af">Inspectors<span style="color: #333333"> inspectors; </span></span></span></span></span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">        <span style="color: blue">private<span style="color: #333333">
<span style="color: blue">void<span style="color: #333333"> ThisAddIn_Startup(<span style="color: blue">object<span style="color: #333333"> sender, <span style="color: #2b91af">EventArgs<span style="color: #333333"> e) </span></span></span></span></span></span></span></span></span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">        { </span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">            inspectors = Application.Inspectors; </span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">            inspectors.NewInspector += Inspectors_NewInspector; </span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">        } </span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333;font-family: Times New Roman"><span style="font-size: 10pt">However, in <em>Inspectors_NewInspector</em> you *<strong>would</strong>* want to call <em>ReleaseCOMObject</em> on <em>inspector</em> once you were done with it.  For example… </span><span style="font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">        <span style="color: blue">private<span style="color: #333333">
<span style="color: blue">void<span style="color: #333333"> Inspectors_NewInspector(Outlook.<span style="color: #2b91af">Inspector<span style="color: #333333"> inspector) </span></span></span></span></span></span></span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">        { </span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">            <span style="color: blue">try </span></span><span style="color: #333333;font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">            { </span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">                <span style="color: #2b91af">MessageBox<span style="color: #333333">.Show(inspector.Caption); </span></span></span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">            } </span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">            <span style="color: blue">finally </span></span><span style="color: #333333;font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">            { </span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">                <span style="color: #2b91af">Marshal<span style="color: #333333">.ReleaseComObject(inspector); </span></span></span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">            } </span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333"><span style="font-family: Arial;font-size: 10pt">        } </span><span style="font-family: Times New Roman;font-size: 10pt">
</span></span>

<span style="color: #333333;font-family: Times New Roman"><span style="font-size: 10pt">You wouldn't want to call <em>ReleaseCOMObject</em> until you were done with that particular reference though.  In this case all the work is done within the try/finally block so we can safely release when we are done.  Also, it is highly recommended that you use a try/finally block to release objects in this scenario because it ensure the reference will get released even if there is an exception.</span><span style="font-size: 10pt">
</span></span>]]></content:encoded>
    </item>
    <item>
      <title>Breaking change to on-premises EWS Push Notifications</title>
      <link>https://docs.microsoft.com/archive/blogs/webdav_101/breaking-change-to-on-premise-ews-push-notifications</link>
      <pubDate>Thu, 14 Feb 2019 05:12:05 GMT</pubDate>
      <dc:creator><![CDATA[Webdav101]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/webdav_101/?p=3075</guid>
      <description><![CDATA[There is a change being introduced to on-premises Exchange servers 2010, 2013, 2016 and 2019 through...]]></description>
      <content:encoded><![CDATA[<p>There is a change being introduced to on-premises Exchange servers 2010, 2013, 2016 and 2019 through cumulative updates which will break existing EWS Push applications which authenticate the notifications sent from Exchange to the listening client.  Every developer and programmer who works with a program that uses EWS Push needs to read the article below and make the needed changes.  All administrators should also read these articles, consider the recommended changes, and reach out to their vendors about possible impact to their application which use EWS Push notifications.  
</p><p>Exchange Web Services Push Notifications can be used to gain unauthorized access<br />    <a href="https://support.microsoft.com/en-ca/help/4490060/exchange-web-services-push-notifications-can-provide-unauthorized-acce">https://support.microsoft.com/en-ca/help/4490060/exchange-web-services-push-notifications-can-provide-unauthorized-acce</a>
	</p><p>The article points to setting a throttling policy for push which will prevent Push notifications from being sent from the server to the client.  
</p><p style="margin-left: 36pt">Set-ThrottlingPolicy<br /><a href="https://docs.microsoft.com/en-us/powershell/module/exchange/server-health-and-performance/set-throttlingpolicy?view=exchange-ps">https://docs.microsoft.com/en-us/powershell/module/exchange/server-health-and-performance/set-throttlingpolicy?view=exchange-ps</a>
	</p><p>Keep in mind that push notifications sent from the server to the EWS listener have very basic information – such as item ids and the event which fired.  </p>]]></content:encoded>
    </item>
  </channel>
</rss>