<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>VSX</title>
        <link>http://geekswithblogs.net/elroydsilva/category/10552.aspx</link>
        <description>VSX</description>
        <language>en-US</language>
        <copyright>Elroy Dsilva</copyright>
        <managingEditor>elroydsilva@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>VSX Add-in Development Adventures: Window.Object returns NULL</title>
            <link>http://geekswithblogs.net/elroydsilva/archive/2009/08/29/vsx-add-in-development-adventures-window.object-returns-null.aspx</link>
            <description>&lt;p&gt;&lt;font size="3" face="Georgia"&gt;I’m in the middle of developing an add-in for Visual Studio 2008, a simple one that would help our in-house code review process. If you’ve ever written a VS add-in, you’d know the basic routine – Visual Studio creates the basic class &lt;font color="#408080"&gt;&lt;strong&gt;Connect&lt;/strong&gt;&lt;/font&gt; derived from &lt;font color="#408080"&gt;&lt;strong&gt;IDTExtensibility2&lt;/strong&gt;&lt;/font&gt;, then you put in your code in the methods OnConnection, OnDisconnection, OnAddInsUpdate, OnStartUpComplete and OnBeginShutdown.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3" face="Georgia"&gt;I developed a few user controls (UserControl objects) for showing some UI as tool windows. One of them was &lt;strong&gt;&lt;font color="#307376"&gt;AddCommentView&lt;/font&gt; &lt;/strong&gt;which is just a dumb UserControl that displays some textboxes and buttons and also takes in some input. I deployed this control as a separate DLL and linked it to the add-in. Then, as usual, the following code should do the job of creating the tool window.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/elroydsilva/WindowsLiveWriter/VSXAddindevelopmentWin.ObjectreturnsNULL_14473/AddCommentView.png" rel="lightbox"&gt;&lt;font face="Georgia"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="AddCommentView" border="0" alt="AddCommentView" src="http://geekswithblogs.net/images/geekswithblogs_net/elroydsilva/WindowsLiveWriter/VSXAddindevelopmentWin.ObjectreturnsNULL_14473/AddCommentView_thumb.png" width="815" height="199" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3" face="Georgia"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3" face="Georgia"&gt;And like always it worked just fine till I tried to test it and that’s when I realized something wasn’t quite right.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;&lt;font face="Georgia"&gt;The &lt;font color="#408080"&gt;&lt;strong&gt;CreateToolWindow2&lt;/strong&gt;&lt;/font&gt; method has two outputs – the tool window (which is returned by the method) and the hosted user control (the ref parameter ‘objTemp’ in this case). The hosted user control can also be retrieved through the &lt;font color="#408080"&gt;&lt;strong&gt;Window.Object &lt;/strong&gt;&lt;/font&gt;&lt;font color="#000000"&gt;property of the returned tool window. The problem was – no matter what I tried the &lt;font color="#408080"&gt;&lt;strong&gt;Window.Object &lt;/strong&gt;&lt;font color="#000000"&gt;property always returned null and so did ‘objTemp’.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/elroydsilva/WindowsLiveWriter/VSXAddindevelopmentWin.ObjectreturnsNULL_14473/RetrieveValues.png" rel="lightbox"&gt;&lt;font face="Georgia"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="RetrieveValues" border="0" alt="RetrieveValues" src="http://geekswithblogs.net/images/geekswithblogs_net/elroydsilva/WindowsLiveWriter/VSXAddindevelopmentWin.ObjectreturnsNULL_14473/RetrieveValues_thumb.png" width="812" height="89" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;font face="Georgia"&gt; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3" face="Georgia"&gt;The solution – I was acting dumb, very dumb. Visual Studio requires all hosted controls to be visible to COM. After adding the attribute to the entire assembly using &lt;strong&gt;[assembly: ComVisible(true)] , &lt;/strong&gt;everything started working like a charm (you can apply it even to the individual control if you don’t want to make the entire assembly COMVisible).&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Georgia"&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134377"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134377" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/elroydsilva/aggbug/134377.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Elroy Dsilva</dc:creator>
            <guid>http://geekswithblogs.net/elroydsilva/archive/2009/08/29/vsx-add-in-development-adventures-window.object-returns-null.aspx</guid>
            <pubDate>Sun, 30 Aug 2009 01:01:49 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/elroydsilva/comments/134377.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/elroydsilva/archive/2009/08/29/vsx-add-in-development-adventures-window.object-returns-null.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/elroydsilva/comments/commentRss/134377.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/elroydsilva/services/trackbacks/134377.aspx</trackback:ping>
        </item>
    </channel>
</rss>