<?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>Ryan's Look at Outlook Programmability : Visual Studio</title><link>http://blogs.msdn.com/rgregg/archive/tags/Visual+Studio/default.aspx</link><description>Tags: Visual Studio</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Mysterious Errors When Using Form Regions from Managed Code Add-ins</title><link>http://blogs.msdn.com/rgregg/archive/2007/06/21/mysterious-errors-when-using-form-regions-from-managed-code-add-ins.aspx</link><pubDate>Fri, 22 Jun 2007 00:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3448498</guid><dc:creator>rgregg</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/rgregg/comments/3448498.aspx</comments><wfw:commentRss>http://blogs.msdn.com/rgregg/commentrss.aspx?PostID=3448498</wfw:commentRss><wfw:comment>http://blogs.msdn.com/rgregg/rsscomments.aspx?PostID=3448498</wfw:comment><description>&lt;P&gt;I've been noticing some feedback lately where a number of developers were having problems working with the controls on their form region.&amp;nbsp; Usually, these problems manifested as Outlook's object model&amp;nbsp;returning null values back when trying to access the Controls collection of the UserForm object in the Microsoft Forms 2.0 library (which was accessed from the FormRegion.Form property).&lt;/P&gt;
&lt;P&gt;This can be especially frustrating, because it looks like you've done everything right, and Outlook is just giving you back something that is totally wrong. Turns out, that isn't quite the case.&lt;/P&gt;
&lt;P&gt;If you've added a reference to the 'Microsoft Forms 2.0' type library, you might have added the wrong reference to your project.&amp;nbsp;On some computers, you'll find two different listings for the forms type library in the Add Reference dialog:&lt;/P&gt;
&lt;P align=center&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rgregg/WindowsLiveWriter/MysteriousErrorsWhenUsingFormRegionsfrom_F2A2/AddReferenceDialog%5B7%5D.jpg" atomicselection="true" mce_href="http://blogs.msdn.com/blogfiles/rgregg/WindowsLiveWriter/MysteriousErrorsWhenUsingFormRegionsfrom_F2A2/AddReferenceDialog%5B7%5D.jpg"&gt;&lt;IMG style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=197 src="http://blogs.msdn.com/blogfiles/rgregg/WindowsLiveWriter/MysteriousErrorsWhenUsingFormRegionsfrom_F2A2/AddReferenceDialog_thumb%5B1%5D.jpg" width=240 border=0 mce_src="http://blogs.msdn.com/blogfiles/rgregg/WindowsLiveWriter/MysteriousErrorsWhenUsingFormRegionsfrom_F2A2/AddReferenceDialog_thumb%5B1%5D.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P align=left&gt;Depending on which reference you select, you'll either get a reference properly associated with the Primary Interop Assembly provided by Office, or you'll get a reference with a Visual Studio generated interop assembly.&amp;nbsp;Unfortuatnely, the VS generated interop assembly incorrectly maps some elements of the type library to elements in the interop assembly.&amp;nbsp; This ultimately means that when you are using this reference, you'll end up calling into a different property or method than your code appears to be calling, which causes various strange exceptions and errors.&lt;/P&gt;
&lt;P align=left&gt;You can easily determine which reference you are using by selecting the reference and looking at the properties of the reference. If you've added the self-generated IA reference, the properties will look like this:&lt;/P&gt;
&lt;P align=center&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rgregg/WindowsLiveWriter/MysteriousErrorsWhenUsingFormRegionsfrom_F2A2/SolutionExplorer_IncorrectReference%5B9%5D.jpg" atomicselection="true" mce_href="http://blogs.msdn.com/blogfiles/rgregg/WindowsLiveWriter/MysteriousErrorsWhenUsingFormRegionsfrom_F2A2/SolutionExplorer_IncorrectReference%5B9%5D.jpg"&gt;&lt;IMG style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=240 src="http://blogs.msdn.com/blogfiles/rgregg/WindowsLiveWriter/MysteriousErrorsWhenUsingFormRegionsfrom_F2A2/SolutionExplorer_IncorrectReference_thumb%5B5%5D.jpg" width=460 border=0 mce_src="http://blogs.msdn.com/blogfiles/rgregg/WindowsLiveWriter/MysteriousErrorsWhenUsingFormRegionsfrom_F2A2/SolutionExplorer_IncorrectReference_thumb%5B5%5D.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P align=left&gt;Notice that the reference has "Copy Local" set to True, and that the Path is not pointing at the Global Assembly Cache (GAC) but rather to the location of my solution.&amp;nbsp; This indicates that I'm using a self-generated interop assembly, and that I may be running into issues.&lt;/P&gt;
&lt;P align=left&gt;If you've added the correct reference to the PIA, then you'll see properties that look like this instead:&lt;/P&gt;
&lt;P align=center&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rgregg/WindowsLiveWriter/MysteriousErrorsWhenUsingFormRegionsfrom_F2A2/SolutionExplorer_CorrectReference%5B3%5D.jpg" atomicselection="true" mce_href="http://blogs.msdn.com/blogfiles/rgregg/WindowsLiveWriter/MysteriousErrorsWhenUsingFormRegionsfrom_F2A2/SolutionExplorer_CorrectReference%5B3%5D.jpg"&gt;&lt;IMG style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=240 src="http://blogs.msdn.com/blogfiles/rgregg/WindowsLiveWriter/MysteriousErrorsWhenUsingFormRegionsfrom_F2A2/SolutionExplorer_CorrectReference_thumb%5B1%5D.jpg" width=460 border=0 mce_src="http://blogs.msdn.com/blogfiles/rgregg/WindowsLiveWriter/MysteriousErrorsWhenUsingFormRegionsfrom_F2A2/SolutionExplorer_CorrectReference_thumb%5B1%5D.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P align=left&gt;This time around, you'll see the Path is pointing into the GAC, and the "Copy Local" property is False. This indicates the PIA is being used, and everything should work normally.&lt;/P&gt;
&lt;P align=left&gt;If you find your project is using the incorrect reference, you should remove the reference and add a new reference.&amp;nbsp; Unforutnately, there is no way to determine which reference is the "right" reference from the Add References dialog.&amp;nbsp; You'll simply need to use trial and error and double check after adding the resource to make sure you've picked the right one.&lt;/P&gt;
&lt;P align=left&gt;&lt;STRONG&gt;The Take-away:&lt;/STRONG&gt; Make sure you are using the right interop assembly when working with custom forms or form regions from your managed code solution.&amp;nbsp; Using the Visual Studio generated interop assembly can cause mysterious errors in your solution that you may not catch right away.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=3448498" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/rgregg/archive/tags/Object+Model/default.aspx">Object Model</category><category domain="http://blogs.msdn.com/rgregg/archive/tags/Forms/default.aspx">Forms</category><category domain="http://blogs.msdn.com/rgregg/archive/tags/Outlook/default.aspx">Outlook</category><category domain="http://blogs.msdn.com/rgregg/archive/tags/.NET/default.aspx">.NET</category><category domain="http://blogs.msdn.com/rgregg/archive/tags/debugging/default.aspx">debugging</category><category domain="http://blogs.msdn.com/rgregg/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://blogs.msdn.com/rgregg/archive/tags/Common+Problems/default.aspx">Common Problems</category></item></channel></rss>