<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Misha Shneerson</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/mshneer/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/mshneer/feed.xml</link>
    <description>VSTO internals and the little things about CLR, COM, Visual Studio and more ...</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:23:21 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>VSTO performance tips</title>
      <link>https://docs.microsoft.com/archive/blogs/mshneer/vsto-performance-tips</link>
      <pubDate>Thu, 03 Jun 2010 11:31:57 GMT</pubDate>
      <dc:creator><![CDATA[Misha Shneerson - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mshneer/2010/06/03/vsto-performance-tips/</guid>
      <description><![CDATA[If you are writing a VSTO customization - make sure you aware of this performance tip courtesy of...]]></description>
      <content:encoded><![CDATA[<p>If you are writing a VSTO customization - make sure you aware of <a href="https://blogs.msdn.com/b/vsto/archive/2010/06/03/vsto-performance-ribbon-reflection.aspx">this performance tip</a> courtesy of Steve Peters - developer on the VSTO team. </p>
<p>This tip allows to prevent VSTO runtime from reflecting on your entry point assembly. We see considerable startup improvements especially for add-ins that have WPF controls - because reflecting on such assemblies means reflecting over some WPF types - these are huge.</p>]]></content:encoded>
    </item>
    <item>
      <title>Oh, that mysteriously broken VisibleSlicerItemsList</title>
      <link>https://docs.microsoft.com/archive/blogs/mshneer/oh-that-mysteriously-broken-visiblesliceritemslist</link>
      <pubDate>Tue, 01 Jun 2010 14:46:05 GMT</pubDate>
      <dc:creator><![CDATA[Misha Shneerson - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mshneer/2010/06/01/oh-that-mysteriously-broken-visiblesliceritemslist/</guid>
      <description><![CDATA[Excel 2010 has a new feature called Slicers and a bunch of new methods and objects associated with...]]></description>
      <content:encoded><![CDATA[<p class="MsoNormal" style="MARGIN: 0in 0in 10pt"><span style="font-family: Calibri; font-size: small;">Excel 2010 has a new feature called <b style="mso-bidi-font-weight: normal">Slicers</b> and a bunch of new methods and objects associated with slicers (I actually am not an expert on Slicers themselves and still need to understand what they are for and how they operate but this leads me to my next point). And there is a </span><span style="FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: 9.5pt">SlicerCache</span><span style="font-family: Calibri; font-size: small;"> object<span style="mso-spacerun: yes">&nbsp; </span>with a property called </span><i style="mso-bidi-font-style: normal"><span style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt">VisibleSlicerItemsList</span></i><span style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt">. </span><span style="font-family: Calibri;"><span style="font-size: small;">I now have heard from several sources that using this property in C# is &hellip; ahem .... putting it nicely &ndash; quite confusing.<o:p></o:p></span></span></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><o:p><span style="font-family: Calibri; font-size: small;">&nbsp;</span></o:p></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="font-family: Calibri;"><span style="font-size: small;">Typically, people would try to cast an object returned by aforementioned property to object[]. This causes an exception stating &ndash; <i style="mso-bidi-font-style: normal">&ldquo;Unable to cast object of type '<b style="mso-bidi-font-weight: normal">System.Object[*]</b>' to type 'System.Object[]&rdquo;</i>. Truth to be told I&rsquo;ve never heard of a type called System.Object[*] so I asked some people that do know and was informed that this merely indicates a non-zero bound array. <span style="mso-spacerun: yes">&nbsp;</span>So, the exception is basically telling us that one cannot cast a non-zero-bound array to a zero-bound array.<span style="mso-spacerun: yes">&nbsp; </span>Great! Now we know that Excel returns a single-dimensional one-bound (i.e. its lowest index is one and not zero) array. We also know that C# does not really have a good syntax to deal with such arrays. Hence we need to go lower. </span></span><span style="font-family: Calibri;"><span style="font-size: small;">Meet System.Array type.<o:p></o:p></span></span></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><o:p><span style="font-family: Calibri; font-size: small;">&nbsp;</span></o:p></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="font-family: Calibri;"><span style="font-size: small;">Armed with this knowledge we could write this code:<o:p></o:p></span></span></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span lang="EN" style="FONT-FAMILY: 'Courier New'; COLOR: green; mso-ansi-language: EN; mso-no-proof: yes"><span style="font-size: small;">// &lt;DOESNT WORK&gt;</span></span><span lang="EN" style="FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: 9.5pt"> </span><span style="FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: 9.5pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: 9.5pt">Workbook</span><span style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"> workbook = <span style="COLOR: #2b91af">Globals</span>.ThisAddIn.Application.ActiveWorkbook;<o:p></o:p></span></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: 9.5pt">SlicerCache</span><span style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"> slicerCache = workbook.SlicerCaches[<span style="COLOR: #a31515">"Slicer_Customer_Geography"</span>];<o:p></o:p></span></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt">System.<span style="COLOR: #2b91af">Array</span> a = (System.<span style="COLOR: #2b91af">Array</span>)(slicerCache.VisibleSlicerItemsList);<o:p></o:p></span></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="font-size: small;"><span lang="EN" style="FONT-FAMILY: 'Courier New'; COLOR: green; mso-ansi-language: EN; mso-no-proof: yes">// &lt;DOESNT WORK&gt;</span><span style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><o:p></o:p></span></span></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><o:p><span style="font-family: Calibri; font-size: small;">&nbsp;</span></o:p></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="font-family: Calibri; font-size: small;">Unfortunately, this would also throw an exception if you are compiling for .NET Fx 4.0 and using C#&rsquo;s new Embed Interop Types aka</span><a href="https://msdn.microsoft.com/en-us/library/dd264728.aspx"><span style="font-family: Calibri; font-size: small;"> /link</span></a><span style="font-size: small;"><span style="font-family: Calibri;"> feature (I really hope you do that because of all the <a href="https://blogs.msdn.com/controlpanel/blogs/posteditor.aspx/wonderful things" title="https://channel9.msdn.com/pdc2008/TL02/">wonderful things</a> you can do with type embedding). This has to do with the fact that using /link also activates C# 4.0&rsquo;s auto-dynamic feature &ndash; meaning methods returning <b style="mso-bidi-font-weight: normal"><i style="mso-bidi-font-style: normal">object</i></b> type are automatically promoted to be <b style="mso-bidi-font-weight: normal"><i style="mso-bidi-font-style: normal"><a href="https://msdn.microsoft.com/en-us/library/dd264736.aspx">dynamic</a> </i></b><i style="mso-bidi-font-style: normal">(</i>see<b style="mso-bidi-font-weight: normal"><i style="mso-bidi-font-style: normal"> </i></b>the COM Interop section on that page). That's exactly our case here since VisibleSlicerItemsList is typed as generic <em>object </em>in the Excel's Primary Interop Assembly. Consequently the cast of <em>dynamic </em>to <i style="mso-bidi-font-style: normal">System.Array</i> is handled by the Dynamic Binder which also does not currently play well with non-zero based arrays. The only way to avoid Dynamic Binder is to cast first to <i style="mso-bidi-font-style: normal">object</i> and then cast back to <i style="mso-bidi-font-style: normal">System.Array:<o:p></o:p></i></span></span></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-FAMILY: Consolas; COLOR: green; FONT-SIZE: 9.5pt">// WORKS</span><span style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: 9.5pt">Workbook</span><span style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"> workbook = <span style="COLOR: #2b91af">Globals</span>.ThisAddIn.Application.ActiveWorkbook;<o:p></o:p></span></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: 9.5pt">SlicerCache</span><span style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"> slicerCache = workbook.SlicerCaches[<span style="COLOR: #a31515">"Slicer_Customer_Geography"</span>];<o:p></o:p></span></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt">System.<span style="COLOR: #2b91af">Array</span> a = (System.<span style="COLOR: #2b91af">Array</span>)(<span style="background-color: #ffff00;">(<span style="color: blue;">object</span>)</span>slicerCache.VisibleSlicerItemsList);<o:p></o:p></span></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-FAMILY: Consolas; COLOR: green; FONT-SIZE: 9.5pt">// WORKS<o:p></o:p></span></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-FAMILY: Consolas; COLOR: green; FONT-SIZE: 9.5pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt"><span style="font-size: small;"><span style="font-family: Calibri;">Live becomes much easier once we do have a System.Array object in hand. Here is the simplest way to iterate over the collection:<o:p></o:p></span></span></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 9.5pt">foreach</span><span style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"> (<span style="COLOR: blue">object</span> slicer <span style="COLOR: blue">in</span> a)<o:p></o:p></span></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>System.Windows.Forms.<span style="COLOR: #2b91af">MessageBox</span>.Show(slicer.ToString());<o:p></o:p></span></p>
<p class="MsoNormal" style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt"><span style="font-size: small;"><span style="font-family: Calibri;">Or, if you prefer the more controlled access to the array &ndash; use Rank property to make sure there is only single dimension to the array, use GetLowerBound/GetUpperBound to determine the boundaries of each dimension and retrieve values using<span style="mso-spacerun: yes">&nbsp; </span>GetValue method.</span></span></p>]]></content:encoded>
    </item>
    <item>
      <title>COM Shim Wizards for VS 2010</title>
      <link>https://docs.microsoft.com/archive/blogs/mshneer/com-shim-wizards-for-vs-2010</link>
      <pubDate>Fri, 19 Mar 2010 17:11:00 GMT</pubDate>
      <dc:creator><![CDATA[Misha Shneerson - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mshneer/2010/03/19/com-shim-wizards-for-vs-2010/</guid>
      <description><![CDATA[About a month ago I wrote a post on compiling the COM shim for 64-bit where I was hoping to have a...]]></description>
      <content:encoded><![CDATA[<P>About a month ago I wrote a <A href="https://blogs.msdn.com/mshneer/archive/2010/02/24/taking-com-shim-wizards-to-64-bit.aspx" mce_href="https://blogs.msdn.com/mshneer/archive/2010/02/24/taking-com-shim-wizards-to-64-bit.aspx">post</A> on compiling the COM shim for 64-bit where I was hoping to have a version of COM Shim Wizards working with Visual Studio 2010. Today I am announcing the coming out of COM Shim Wizards for VS 2010 … I am calling it "coming out" and not a binding word "release" simply because it is not a release. All I am going to do is attach an MSI package to this blog post and explain what you will get when you install this file on your machine. I am not promising any support - although I am not denying that, as long as I am interested in this area, I will try to fix issues if they are reported in the comments to this post. Again, this is not an official release from Microsoft but just something I have done in my spare time because long time ago I was fortunate enough to work with Andrew Whitechapel and Siew Moi Khor to start it all. </P>
<P>For the information on why it is important to isolate shared add-ins using a COM shim please refer to this <A href="https://msdn.microsoft.com/en-us/library/aa159894(office.11).aspx" mce_href="https://msdn.microsoft.com/en-us/library/aa159894(office.11).aspx">article</A>. You can find here all the details why and how you need to digitally sign the shim and also how shim provides certain level of isolation for the managed add-in by placing it in a separate AppDomain. </P>
<P>There is a separate <A href="https://msdn.microsoft.com/en-us/library/bb508939.aspx" target=_blank mce_href="https://msdn.microsoft.com/en-us/library/bb508939.aspx">article explaining the architecture of the shimmed solution</A>&nbsp;and also shows how to use the COM Shim Wizards to easily create a shim around your existing managed add-in. </P>
<P>So, let's start enumerating the changes the COM Shim Wizards went through when compared to the one we had in the <A href="https://msdn.microsoft.com/en-us/library/bb508939.aspx" mce_href="https://msdn.microsoft.com/en-us/library/bb508939.aspx">last release</A>: </P>
<UL>
<LI>The MSI package attached to this post will install project templates for Visual Studio 2010 only. Notice that VS 2010 should be installed on the machine first. There is no option to install to VS 2008 / VS 2005. </LI>
<LI>Only the project template for AddIn Shim is now installed. Shims for RealTimeData and SmartTags were dropped – neither I or Andrew saw a lot of demand for these and we decided to not invest the required time into the required support. </LI>
<LI>When harvesting information from the assembly we have a new data field called "Image Version". This data is important. In particular if the image's version v2.0.50727 – the generated shim will use CLR 1.0 hosting interfaces, if the image's version is different – the generated shim will use CLR 4.0 hosting interfaces. I explain the nuances about hosting interfaces below. </LI>
<LI>Fixed the bugs in ManagedAggregator.cs and CLRLoader.cpp that could cause the host application to not property shutdown (see the comment in the <A href="https://msdn.microsoft.com/en-us/library/bb508939.aspx" mce_href="https://msdn.microsoft.com/en-us/library/bb508939.aspx">MSDN article</A> regarding these bugs) </LI>
<LI>As in the last release, the created shim is a 32-bit native DLL. Please follow the steps outlined in the <A href="https://blogs.msdn.com/mshneer/archive/2010/02/24/taking-com-shim-wizards-to-64-bit.aspx" mce_href="https://blogs.msdn.com/mshneer/archive/2010/02/24/taking-com-shim-wizards-to-64-bit.aspx">"Taking COM Shim Wizards to 64-bit"</A> to compile a 64-bit version </LI></UL>
<H2>CLR Hosting Interfaces </H2>
<P>The way we host CLR is the only significant change in the code that is being generated by the AddIn Shim template. In the previous version of the shim we used what is called CLR 1.0 Hosting Interfaces – i.e. these are the hosting interfaces that were available in the initial release of .NET Framework 1.0 </P>
<P>The assumption back then was that only one version of the CLR can be loaded into the process. This assumption lasted through .NET Fx 3.5. However, CLR 4.0 allows <A href="https://msdn.microsoft.com/en-us/magazine/ee819091.aspx" mce_href="https://msdn.microsoft.com/en-us/magazine/ee819091.aspx">hosting multiple versions of CLR side-by-side</A> in the same process and the hosting interfaces needed to reflect this. </P>
<P>Some hard decisions had to be made and one of those decisions is that using CLR 1.0 hosting interfaces is only good to host CLR versions up to 2.0 (i.e. .NET Framework 3.5). The only way to host .NET Framework 4.0 as well as future version of .NET is by using the <A href="https://msdn.microsoft.com/en-us/library/dd380851(VS.100).aspx" mce_href="https://msdn.microsoft.com/en-us/library/dd380851(VS.100).aspx">new hosting interfaces</A>. </P>
<P>So, how do you decide whether you want to use the new hosting interfaces or the legacy hosting interfaces? My thinking is that if you compiled against CLR 2.0 – you probably want to run in the CLR 2.0 and not require CLR 4.0 to be installed– so you will use the legacy hosting interfaces to load the CLR 2.0. </P>
<P>On the other hand if you compiled against CLR 4.0 or above – you have to use the new hosting interfaces to load CLR 4.0 or above. </P>
<P>To control which hosting interfaces to use you only need to comment out/ uncomment one line of code in CLRLoader.cpp file that is generated by the wizard. This line is at the very top of the file and is accompanied by a hefty comment: </P>
<P><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9pt"><SPAN style="COLOR: green">// When loading assemblies targeting CLR 4.0 and above make sure</SPAN> </SPAN></P>
<P><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9pt"><SPAN style="COLOR: green">// the below line is NOT commented out. It enables starting</SPAN> </SPAN></P>
<P><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9pt"><SPAN style="COLOR: green">// CLR using new hosting interfaces available in CLR 4.0 and above.</SPAN> </SPAN></P>
<P><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9pt"><SPAN style="COLOR: green">// When below line is commented out the shim will use legacy interfaces </SPAN></SPAN></P>
<P><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9pt"><SPAN style="COLOR: green">// which only allow loading CLR 2.0 or below.</SPAN> </SPAN></P>
<P><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9pt"><SPAN style="COLOR: blue">#define</SPAN> USE_CLR40_HOSTING </SPAN></P>
<P>By default, when we harvest the version information from the assembly we will also detect which CLR runtime the assembly is targeting – this information is available in the assembly's metadata and the Assembly Harvesting step of the wizard displays this information in the "Image Version" field. If the assembly has been compiled against CLR 2.0 - the "Image Version" field will show v2.0.5727 – the above "magic" line of code will be commented out when the files are generated. </P>
<P>However, if the "Image Version" does not start with v2 – the "magic" line is uncommented and this causes new hosting interfaces to be used to load the CLR </P>
<P>Notice that in order to use the new hosting interfaces CLR 4.0 (or above) is required to be installed on the machine. The shim compiled to use new hosting interfaces will fail to load if CLR 4.0 (or above) is missing. </P>
<P>When using the new hosting interfaces it is possible to load any version of the CLR installed on the box. So, the logic we are using goes like this – we first try to load the same version of the CLR the image was compiled against. This, however, can fail e.g. because this particular versoin is not installed. In this case, the shim will enumerate all the CLRs installed on the machine and pick up the latest one. The decision is made in <SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9pt">BindToCLR4OrAbove </SPAN>function in CLRLoader.cpp. I am mentioning this just in case you would like to play with it. </P>
<P>Some sharp minds may have noticed that it is possible to use new hosting interfaces to load CLR 2.0 – however, I wanted to call out that this may not be the best course of action since you would still be requiring CLR 4.0 to be installed on the machine. </P>
<H3>Debugging add-ins targeting CLR 2.0 in Visual Studio 2010 </H3>
<P>I had some problems debugging add-ins if those were loading in CLR 2.0. I would press F5, Excel would start up and my add-in would run but the breakpoints were not getting hit. So I wanted to share what's going on and how to set up your environment in such a way that F5 experience is not completely broken. </P>
<P>There is no magic in the way I usually go about debugging the shared add-in - either shimmed or unshimmed. I set a breakpoint in the OnConnection method in Connect.cs file, open project's properties, go to the Debug section, select the "Start External Program" option and set the full path to my Office application (e.g. "C:\Program Files\Microsoft Office\Office12\EXCEL.EXE"). Next I right click on the project node in the Solution Explorer and select "Set As Startup Project". When I press F5 my breakpoint is hit. </P>
<P>In Visual Studio 2010 the breakpoint is not hit if my add-in is loaded in CLR 2.0. What's going on is that debugger cannot attach to both CLR 4.0 and CLR 2.0 - it actually needs to know before the fact whether it should be using CLR 2.0 debugging engine or CLR 4.0 debugging engine. When you press F5 debugger tries to guess which CLR will be started in the process. The heuristic is based on reading the EXE's .config file where required runtime version is u8sually specified and if the .config file is not found than the debugger fires up the CLR 4.0 debugging engine. As we all know Office application are not bound to any particular version of the CLR so the heuristic miserably fails. </P>
<P>There are actually two ways of dealing with it – one is to put an &lt;YourApp&gt;.exe.config file alongside the.exe itself e.g. when debugging Excel 2007 I will create Excel.exe.config and leave it in the "C:\Program Files\Microsoft Office\Office12" folder. </P>
<P>But my preferred way of dealing with this is different. In the Solution Explorer I will right click on my solution node and select "Add" -&gt; "Existing Project" and open "C:\Program Files\Microsoft Office\Office12\EXCEL.EXE". Next, I will right click on this newly added project and select "Set As Startup Project". Next, I will open the properties for this project and will set the "Debugger Type" property to "Managed (v2.0, v1.1, v1.0)". Now, I will F5 and the breakpoint I've set in OnConnection method will be hit. </P>
<P>Happy shimming everyone! </P>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/09/98/21/95/COMShimWizardSetup.msi" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-09-98-21-95/COMShimWizardSetup.msi">COMShimWizardSetup.msi</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Design of VSTO 2010 runtime</title>
      <link>https://docs.microsoft.com/archive/blogs/mshneer/design-of-vsto-2010-runtime</link>
      <pubDate>Wed, 10 Mar 2010 16:57:00 GMT</pubDate>
      <dc:creator><![CDATA[Misha Shneerson - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mshneer/2010/03/10/design-of-vsto-2010-runtime/</guid>
      <description><![CDATA[When migrating VSTO solutions targeting .NET 3.5 to .NET 4.0 people are noticing some design...]]></description>
      <content:encoded><![CDATA[<P>When migrating VSTO solutions targeting .NET 3.5 to .NET 4.0 people are noticing some design changes. Our <A href="https://msdn.microsoft.com/en-us/vsto/ee207231(VS.100).aspx" mce_href="https://msdn.microsoft.com/en-us/vsto/ee207231(VS.100).aspx">documentation on migration</A> puts it pretty straightforward about this and does not explain the underlying reasoning for these changes:</P>
<P><EM>"If the target framework of an Office project is changed to the .NET Framework&nbsp;4 from an earlier version of the .NET Framework, some additional steps might be required&nbsp;to continue to run the solution on development and end user computers"</EM></P>
<P>I though I will re-use the old email thread on the issue and hopefully some people can find this information useful. Below is the slightly edited copy&amp;paste of the email. It contains some abbreviations that might not be obvious so here is rough translation table:</P>
<P>M.O.T = Microsoft.Office.Tools<BR>M.VS.T.A. = Microsoft.VisualStudio.Tools.Application<BR>NoPIA = CLR 4.0 functionality for Type Equivalence and Type Embedding. It can be activated in Visual Studio 2010 by setting "Embed Interop Types"&nbsp;&nbsp;property on the assembly referenes to 'True'</P>
<P><B><SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt">From:</SPAN></B><SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"> Misha Shneerson <BR><B>Subject:</B> RE: Bug Discussion on VSTO Technology<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face="Times New Roman">&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB><EM>&gt; Since then though my solution is looking to distribute the new <B><SPAN style="BACKGROUND: yellow; mso-highlight: yellow">utilities.v4</SPAN></B> assemblies and causing a distribution issue at the moment, could you elaborate a little on this so can help me understand.<o:p></o:p></EM></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>This is actually by design. Let me try and explain the overall picture and where the utilities assemblies fit in.<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>All our new core assemblies with public APIs – i.e. M.O.T.Common, M.O.T.Excel etc (well, that’s all except M.VS.T.A.Runtime.dll) do contain interfaces. This is instead of classes that the user code derived from in the previous version.<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>So, for example, Microsoft.Office.Tools.Excel.Workbook is now an interface.<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><B><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>At this point you should be going like “Huh! Why in the world would they do that?”.<o:p></o:p></SPAN></B></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>In CLR4 there is a new feature available which is codenamed NoPIA (I hope you did hear about this – if not there are couple of posts on my blog on the topic) where the original idea is that compilers will embed PIA interfaces (thus creating local copy of the interface in the assembly itself) and CLR will consider multiple copies of the same interface to be equivalent. Basically, that means that if assembly A has a method Foo(M.O.I.Excel.Application xlapp) and assembly B wants to call Foo(xlapp) – each one will operate on its own copy of the M.O.I.Excel.Application interface but the code will still work. And all this w/o even loading Microsoft.Office.Interop.Excel.dll into memory!<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>So, we have applied same NoPIA principles to VSTO Object Model as well – VSTO’s core OM now consists of interfaces which do qualify for type equivalence.<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>So, why we are doing all this? This is actually to allow VSTO runtime and VSTO code to version independently of each other. I.e. if the user code does take dependency on VSTO’s runtime assembly – and then we rev up our runtime (and all assemblies that come with it) – we still want to load the same code w/o recompilation. Using interfaces and type equivalence allow us to do so.<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><B><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>Now, everything is good – so why all these Utilities assemblies and what are they for? <o:p></o:p></SPAN></B></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><B><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB><o:p>&nbsp;</o:p></SPAN></B></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>In the past user’s ThisWorkbook derived from VSTO’s Microsoft.Office.Tools.Excel.Workbook class. This did allow for some very nice syntax where developers could write their code using familiar VBA notation e.g. Me.ActiveSheet. <o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>But the problem with making Microsoft.Office.Tools.Excel.Workbook an interface is that now user code cannot derive from this interface. In order to maintain the nice old Me.XXX syntax we needed user’s ThisWorkbook to derive from another class which just redirects all its calls to Microsoft.Office.Tools.Excel.Workbook interface. Now, welcome to Microsoft.Office.Tools.Excel.WorkbookBase class in the Utilities assembly! That’s exactly what it is doing – just redirecting calls to M.O.T.Workook interface methods. Actually, if you look into the Utilities assembly you will see that all of these are just thin calls through on methods from one or another interface.<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>The bad part is that the versioning of classes is different than versioning of interfaces. But since user code takes dependency on these Utilities assemblies – those assemblies and user assemblies are now tightly coupled together and need to be deployed together (e.g. if VSTO runtime would rev up those assemblies and user code tried to bind to the rev’d up assemblies – it would fail). From the versioning perspective user code and utilities assemblies are now one coherent unit. This coherent unit talks to VSTO runtime classes through interfaces.<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>We feel safe for the developers to deploy these assemblies alongside with their code since we never intend to services these (these are just thin wrappers w/o state/code or anything that would require servicing).<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><B><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>What is the guidance around the core VSTO OM interfaces? How they version and can developers implement those interfaces.<o:p></o:p></SPAN></B></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><B><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB><o:p>&nbsp;</o:p></SPAN></B></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>Typical question I expect to hear is “Since M.O.T.Excel.Workbook is an interface – can developer just implement this interface to provide custom behaviour for some of Workbook methods?”. The short answer is – NO, do not implement these interfaces.<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>The long answer is – VSTO reserves the right to version these interfaces in the future versions. I.e. we want to be able to add new methods to these interfaces (similarly to what Office does with its interfaces). If we add new methods that user code does not implement – something will be broken there, either compile time or runtime or, most probably, both.<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>So, in our documentation we will specify which interfaces are expected to be implemented by the user. The rule of thumb is – <B><I>if interface’s name starts with ‘I’ e.g. IExtension, IWorkbookExtension, ISmartTagExtension – the interface can be implemented by 3<SUP>rd</SUP> parties – it is locked down and we guarantee to not modify it in next version.<o:p></o:p></I></B></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>Hope this helps to clarify the picture,<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>Misha<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><B><SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt">From:</SPAN></B><SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"> ...</SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"><B>To:</B> Misha Shneerson; Rachel Falzone Schaw<BR><B>Subject:</B> RE: Bug Discussion on VSTO Technology<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face="Times New Roman">&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB><o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>I have managed to get a little further, one of the developers had changed the Codebehind Partial class and this rename had knocked out the build and then it was me trying to reference old assemblies that caused the problem. I have since created a fresh project and noticed that the utilities class had the functionality and it was looking for a needle in a haystack because was a simple case naming error in my class </SPAN><SPAN style="FONT-FAMILY: Wingdings; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>L</SPAN><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>.. Since then though my solution is looking to distribute the new utilities.v4 assemblies and causing a distribution issue at the moment, could you elaborate a little on this so can help me understand.<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt; mso-ansi-language: EN-GB" lang=EN-GB>Thanks for your response.<o:p></o:p></SPAN></P>
<P mce_keep="true">&nbsp;</P>]]></content:encoded>
    </item>
    <item>
      <title>Taking COM Shim Wizards to 64-bit</title>
      <link>https://docs.microsoft.com/archive/blogs/mshneer/taking-com-shim-wizards-to-64-bit</link>
      <pubDate>Wed, 24 Feb 2010 17:12:00 GMT</pubDate>
      <dc:creator><![CDATA[Misha Shneerson - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mshneer/2010/02/24/taking-com-shim-wizards-to-64-bit/</guid>
      <description><![CDATA[It’s been quite a while since the last update to COM Shim Wizards has taken place. Among the things...]]></description>
      <content:encoded><![CDATA[<P><FONT color=#800040>It’s been quite a while since the </FONT><A href="https://blogs.msdn.com/andreww/archive/2008/08/27/com-shim-wizard-2-3-1-0.aspx" mce_href="https://blogs.msdn.com/andreww/archive/2008/08/27/com-shim-wizard-2-3-1-0.aspx"><FONT color=#800040>last update</FONT></A><FONT color=#800040> to COM Shim Wizards has taken place. Among the things that have happened since are the new versions of Visual Studio (i.e. Visual Studio 2010) and Office (Office 2010). Both products are close to go out so it is time to do some face-lifting to the wizards as well. </FONT></P>
<P><FONT color=#800040>Ideally I would love to announce that we have released a version of COM Shim wizards that is working with VS 2010 – but this is not the case yet and in fact I haven’t started investigating yet what would it take to make this work. So, while I am looking for answers there, you can use the wizards on VS 2008 and then migrate your solutions to VS 2010. I know such solution is less than ideal so please accept my apologies…</FONT></P>
<P><FONT color=#800040>UPDATE March 23 2010 - Version of COM Shim wizards for VS 2010 is <A href="https://blogs.msdn.com/mshneer/archive/2010/03/19/com-shim-wizards-for-vs-2010.aspx" mce_href="https://blogs.msdn.com/mshneer/archive/2010/03/19/com-shim-wizards-for-vs-2010.aspx">now available</A></FONT></P>
<P><FONT color=#800040>Another question is how to get a working 32-bit shim wizard to <STRONG>work with 64-bit of Office</STRONG>. That’s the question that I want to address in this post. </FONT></P>
<P><FONT color=#800040>The environment I am working in is as follows:</FONT></P>
<UL>
<LI><FONT color=#800040>Windows 7 64-bit</FONT> </LI>
<LI><FONT color=#800040>Visual Studio 2008 RTM</FONT> </LI>
<LI><FONT color=#800040>Excel 2010 64-bit (Release Candidate of Microsoft Office Professional Plus 2010 64-bit)</FONT> </LI></UL>
<P><FONT color=#800040>For the information on why it is important to isolate shared add-ins using COM shim please refer to this <A href="https://msdn.microsoft.com/en-us/library/aa159894(office.11).aspx" mce_href="https://msdn.microsoft.com/en-us/library/aa159894(office.11).aspx">article</A>. You can find here all the details why and how you need to digitally sign the shim and also how shim provides certain level of isolation for the managed add-in by placing it in a separate AppDomain.</FONT></P>
<P><FONT color=#800040>There is a separate <A href="https://msdn.microsoft.com/en-us/library/bb508939.aspx" target=_blank mce_href="https://msdn.microsoft.com/en-us/library/bb508939.aspx">article explaining the architecture of the shimmed solution</A>&nbsp;and also shows how to use the COM Shim Wizards to easily create shim around your existing managed add-in.</FONT></P>
<P><FONT color=#800040>The first thing I am going to do is create a simple Shared Add-In for Excel 2010 called DemoTest so if you already know how to do this then just skip this part.</FONT></P>
<H2>Creating basic shared add-in</H2>
<P><FONT color=#800040>In VS 2008 I opened the “New Project” dialog and selected “Other Project Types” –&gt; “Extensibility” –&gt; “Shared Add-in”:</FONT></P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/NewProj_2.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/NewProj_2.png" mce_href="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/NewProj_2.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=NewProj border=0 alt=NewProj src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/NewProj_thumb.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/NewProj_thumb.png" width=244 height=166 mce_src="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/NewProj_thumb.png"></A> </P>
<P><FONT color=#800040>Here are the options that I have selected in the Shared Add-In Wizard :</FONT></P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard1_4.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard1_4.png" mce_href="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard1_4.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=Wizard1 border=0 alt=Wizard1 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard1_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard1_thumb_1.png" width=244 height=188 mce_src="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard1_thumb_1.png"></A> <A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard2_4.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard2_4.png" mce_href="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard2_4.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=Wizard2 border=0 alt=Wizard2 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard2_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard2_thumb_1.png" width=244 height=188 mce_src="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard2_thumb_1.png"></A> <A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard3_4.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard3_4.png" mce_href="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard3_4.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=Wizard3 border=0 alt=Wizard3 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard3_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard3_thumb_1.png" width=244 height=188 mce_src="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard3_thumb_1.png"></A> <A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard4_4.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard4_4.png" mce_href="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard4_4.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=Wizard4 border=0 alt=Wizard4 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard4_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard4_thumb_1.png" width=244 height=188 mce_src="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/Wizard4_thumb_1.png"></A> </P>
<P><FONT color=#800040>Upon wizard completion I can see 2 projects created for me: DemoTest and DemoTestSetup</FONT></P>
<P><FONT color=#800040>So, the first thing that I want to see is my add-in running. To do that I will add a simple message box to the OnConnection method, compile and start up Excel.</FONT></P>
<P><FONT color=#800040>Well, I did not see the message box and looking at Excel’s “COM Add-Ins” dialog I can see that Excel has no idea it needs to load an add-in:</FONT></P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/COMADDIN_NoAddIn_4.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/COMADDIN_NoAddIn_4.png" mce_href="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/COMADDIN_NoAddIn_4.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=COMADDIN_NoAddIn border=0 alt=COMADDIN_NoAddIn src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/COMADDIN_NoAddIn_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/COMADDIN_NoAddIn_thumb_1.png" width=244 height=107 mce_src="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/COMADDIN_NoAddIn_thumb_1.png"></A> </P>
<P><FONT color=#800040>Calling upon my psychic powers I conclude that the add-in is only registered for 32-bit Office and so 64-bit Office is completely oblivious to it. Time to do some registry hacking! </FONT></P>
<P><FONT color=#800040>&lt;start registry hacking&gt;</FONT></P>
<P><FONT color=#800040>Open regedit tool and navigate to <EM>HKEY_LOCAL_MACHINE\SOFTWARE\<STRONG>Wow6432Node</STRONG>\Microsoft\Office\Excel\Addins\DemoTest.Connect</EM>, right click on this key and export it into a .reg file e.g. %temp%\addin.reg%</FONT></P>
<P><FONT color=#800040>Next, let’s open <EM>HKEY_CLASSES_ROOT\DemoTest.Connect\CLSID</EM> key and notice that the (Default) value of this key on my machine is <EM>{DD16A145-E2F0-40B9-9993-5018BA8B64B3} </EM>(NOTICE: this value must be different for you. In fact, it must be unique for every add-in. During project creation such unique value is created and stored as the value of the <EM>Guid </EM>attribute on the Connect class in Connect.cs). In order to reduce the confusion I will further refer to this cryptic string as just a bunch of Xs e.g. {XXXX}.</FONT></P>
<P><FONT color=#800040>Now let’s open <EM>HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{XXXX} </EM>key and export it to %temp%\clsid.reg</FONT></P>
<P><FONT color=#800040>Using notepad.exe open %temp%\addin.reg, remove all occurrences of <EM>Wow6432Node\ </EM>and save the file, repeat for %temp%\clsid.reg</FONT></P>
<P><FONT color=#800040>Go back to regedit. Use File-&gt;Import command to import %temp%\addin.reg first, then repeat the same with %temp%\clsid.reg</FONT></P>
<P><FONT color=#800040>&lt;end registry hacking&gt;</FONT></P>
<P><FONT color=#800040>Opening Excel 2010 now produces the desired result – our little message box shows up:</FONT></P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/MsgBoxOnConnection_4.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/MsgBoxOnConnection_4.png" mce_href="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/MsgBoxOnConnection_4.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=MsgBoxOnConnection border=0 alt=MsgBoxOnConnection src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/MsgBoxOnConnection_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/MsgBoxOnConnection_thumb_1.png" width=244 height=164 mce_src="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/MsgBoxOnConnection_thumb_1.png"></A> </P>
<P><FONT color=#800040>This exercise shows that pure IL code is platform agnostic - same exact assembly will run without recompilation in both 32- and 64-bit Office processes. Unfortunately, this is not the case with native code and since COM shim for the managed add-in is written in native code it needs to be recompiled.</FONT></P>
<H3>Creating a 64-bit shim for the basic shared add-in</H3>
<P><FONT color=#800040>Now, for myriad of reasons mentioned elsewhere, we need to shim the add-in. I have already re-read the article <A href="https://blogs.msdn.com/andreww" mce_href="https://blogs.msdn.com/andreww">Andrew Whitechapel</A> and I wrote a while ago (and I am assuming you’ve done so as well so that we are on the same page) and now I am able to zoom through all the options of the COM shim wizard to create my shim project. Once the wizard is completed we now have 2 new projects added to our solution:</FONT></P>
<UL>
<LI><FONT color=#800040>ManagedAggregator</FONT> </LI>
<LI><FONT color=#800040>DemoTestShim</FONT> </LI></UL>
<P><FONT color=#800040><STRONG>Important:</STRONG> check out the fixes to the code that you are getting from the wizards – <STRONG>COM Shim 2.3.1.0 Bug Fixes </STRONG>fixes are located at the very bottom of the <A href="https://msdn.microsoft.com/en-us/library/bb508939.aspx" mce_href="https://msdn.microsoft.com/en-us/library/bb508939.aspx">article</A></FONT></P>
<P><FONT color=#800040>Notice that our solution builds 3 DLLs: 2 managed (both are platform agnostic) and 1 native (this one is currently targeting 32-bit platforms). Now we need to configure our solution so that we can build 64-bit native DLL . To do that we need to use Configuration Manager (available through the menu Build –&gt; Configuration Manager …). In the “Active Solution” combo box select “&lt;New…&gt;” and this will bring up the New Solution Platform dialog where you need to select the platform you want to target. Here are the choices I made:</FONT></P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/NewSolDlg_2.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/NewSolDlg_2.png" mce_href="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/NewSolDlg_2.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=NewSolDlg border=0 alt=NewSolDlg src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/NewSolDlg_thumb.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/NewSolDlg_thumb.png" width=244 height=153 mce_src="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/NewSolDlg_thumb.png"></A> </P>
<P><FONT color=#800040>Once you press ‘OK’ all the project in your new x64 configuration will now target x64 – we want to revert both managed projects back to target Any CPU.</FONT></P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/ConfigMgr_2.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/ConfigMgr_2.png" mce_href="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/ConfigMgr_2.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=ConfigMgr border=0 alt=ConfigMgr src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/ConfigMgr_thumb.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/ConfigMgr_thumb.png" width=244 height=153 mce_src="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/ConfigMgr_thumb.png"></A> </P>
<P><FONT color=#800040>Now, we are almost ready to compile the project. One little thing that is left to do is to fix the location where Framework and Windows SDK libraries are picked up from for 64-bit compilation. So, right click on DemoTestShim project, select Properties and navigate to </FONT><FONT color=#800040>Configuration Properties -&gt; Linker -&gt; General <BR>Find "Additional Library Properties" setting and append "\x64" to the already existing "$(FrameworkSDKDir)lib" to make it "$(FrameworkSDKDir)lib\x64" </FONT></P>
<P><FONT color=#800040><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/CPPConfig_4.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/CPPConfig_4.png" mce_href="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/CPPConfig_4.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=CPPConfig border=0 alt=CPPConfig src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/CPPConfig_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/CPPConfig_thumb_1.png" width=299 height=210 mce_src="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/CPPConfig_thumb_1.png"></A> </FONT></P>
<P><FONT color=#800040>Now let’s compile and run Excel, bring up the COM Add-Ins dialog and we can see that our add-in is being loaded through the 64 bit shim we just compiled</FONT></P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/COMADDIN_shimmed_2.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/COMADDIN_shimmed_2.png" mce_href="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/COMADDIN_shimmed_2.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=COMADDIN_shimmed border=0 alt=COMADDIN_shimmed src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/COMADDIN_shimmed_thumb.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/COMADDIN_shimmed_thumb.png" width=296 height=129 mce_src="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/COMADDIN_shimmed_thumb.png"></A> </P>
<H2>Fixing up the deployment project</H2>
<P><FONT color=#800040>Let’s not forget about the setup project that is there for us. By making the right adjustments we can get a nice MSI that is capable of deploying our shimmed add-in to 64-bit consumers.</FONT></P>
<P><FONT color=#800040>First of all, I opened the File System view for the deployment project (DemoTestSetup) and added the outputs for both the DemoTestShim and the ManagedAggregator projects to the Application Folder</FONT></P>
<P><FONT color=#800040><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/FileSystem_2.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/FileSystem_2.png" mce_href="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/FileSystem_2.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=FileSystem border=0 alt=FileSystem src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/FileSystem_thumb.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/FileSystem_thumb.png" width=294 height=108 mce_src="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/FileSystem_thumb.png"></A> </FONT></P>
<P><FONT color=#800040>I also verified that none of these components will be self-registering by setting the Register property for each one of these to vsdrpDoNotRegister.</FONT></P>
<P><FONT color=#800040>Next, I specified that my setup package is targeting x64 platform (TargetPlatform=x64). Additionally, I want this package to be installed for All Users on a machine (InstallAllUsers=True).</FONT></P>
<P><FONT color=#800040><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/setupprops_2.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/setupprops_2.png" mce_href="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/setupprops_2.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=setupprops border=0 alt=setupprops src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/setupprops_thumb.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/setupprops_thumb.png" width=294 height=295 mce_src="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/setupprops_thumb.png"></A> </FONT></P>
<P><FONT color=#800040>One last thing that is left to do is to add the correct registry keys to the Registry View. The the registry view that I currently have only contains the HKLM\Software\Microsoft\Office\Excel\AddIns\DemoTest.Connect</FONT></P>
<P><FONT color=#800040>We are missing HKCR\DemoTest.Connect key and HKCR\CLSID\{XXXX} key. To add both of these keys:</FONT></P>
<P><FONT color=#800040>1. Open regedit and navigate to HKCR\CLSID\{XXXX}&nbsp;</FONT></P>
<P><FONT color=#800040>2. Right click and export this registry key to %temp%\clsid.reg</FONT></P>
<P><FONT color=#800040>3. In Registry View in VS right click on Registry on Target Machine, click Import … and select %temp%\clsid.reg</FONT></P>
<P><FONT color=#800040>4. Modify the (Default) value for CLSID\{XXXX}\InprocServer32 to point to the location where the shim will be installed. For me I need to change c<EM>:\Temp\DemoTest\DemoTestShim\x64\Debug\DemoTestShim.dll </EM>to [TARGETDIR]DemoTestShim.dll</FONT></P>
<P><FONT color=#800040>5. Open regedit and navigate to HKCR\DemoTest.Connect and export it to %temp%\progid.reg</FONT></P>
<P><FONT color=#800040>6. Back in VS’s Registry View import %temp%\progid.reg</FONT></P>
<P><FONT color=#800040>That’s it! The deployment project should be ready.</FONT></P>
<P><FONT color=#800040></FONT></P>
<H2><FONT color=#800040></FONT></H2>
<H2>Installing and Running the packaged add-in</H2>
<P><FONT color=#800040>Let’s compile the entire solution, right click on the DemoTestSetup project node in the Solution Explorer , choose “Install…” and complete the installation process.</FONT></P>
<P><FONT color=#800040>Now open Excel and see your add-in happily loaded through the shim that was installed under %ProgramFiles% folder!</FONT></P>
<P><FONT color=#800040><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/COMADDIN_FromProgramFiles_2.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/COMADDIN_FromProgramFiles_2.png" mce_href="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/COMADDIN_FromProgramFiles_2.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=COMADDIN_FromProgramFiles border=0 alt=COMADDIN_FromProgramFiles src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/COMADDIN_FromProgramFiles_thumb.png" original-url="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/COMADDIN_FromProgramFiles_thumb.png" width=375 height=174 mce_src="https://blogs.msdn.com/blogfiles/mshneer/WindowsLiveWriter/TakingCOMShimWizardsto64bit_F883/COMADDIN_FromProgramFiles_thumb.png"></A></FONT></P>
<P><FONT color=#800040>Happy shimming to everyone, now available on 64-bit! My sample solution is attached for all your exploratory needs.</FONT></P>
<P><FONT color=#800040></FONT>&nbsp;</P>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/09/96/89/85/DemoTest.zip" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-09-96-89-85/DemoTest.zip">DemoTest.zip</a></p>]]></content:encoded>
    </item>
    <item>
      <title>NoPIA blog posts</title>
      <link>https://docs.microsoft.com/archive/blogs/mshneer/nopia-blog-posts</link>
      <pubDate>Fri, 29 Jan 2010 14:42:00 GMT</pubDate>
      <dc:creator><![CDATA[Misha Shneerson - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mshneer/2010/01/29/nopia-blog-posts/</guid>
      <description><![CDATA[The plan of record for this post is to collect refererences to NoPIA related posts by other folks...]]></description>
      <content:encoded><![CDATA[<P>The plan of record for this post is to collect refererences to NoPIA related posts by other folks whose opinion I cherish. I wish the list would update automatically when somebody has something smart to say about this stuff but not sure the technology is there yet. So I will try to play the role of automatic updates&nbsp;system as best as I can. So here we go:</P>
<P>1. Video: Raja Krishnaswamy and Jesse Kaplan from the CLR <A href="https://channel9.msdn.com/posts/Charles/Raja-Krishnaswamy-and-Jesse-Kaplan-CLR-4-Inside-No-PIA/" mce_href="https://channel9.msdn.com/posts/Charles/Raja-Krishnaswamy-and-Jesse-Kaplan-CLR-4-Inside-No-PIA/">discuss</A> the NoPIAssness aspect of the feature on Channel9</P>
<P>2. Video: Raja and Vance Morrison from the CLR <A href="https://channel9.msdn.com/posts/Charles/Raja-Krishnaswamy-and-Jesse-Kaplan-CLR-4-Inside-No-PIA/" mce_href="https://channel9.msdn.com/posts/Charles/Raja-Krishnaswamy-and-Jesse-Kaplan-CLR-4-Inside-No-PIA/">discuss</A> the Type Equivalence aspect of NoPIA on Channel9 and the intricacies of the type system</P>
<P>3. Blog Post: Sam Ng <A href="https://blogs.msdn.com/samng/archive/2010/01/24/the-pain-of-deploying-primary-interop-assemblies.aspx" mce_href="https://blogs.msdn.com/samng/archive/2010/01/24/the-pain-of-deploying-primary-interop-assemblies.aspx">introduces</A> Type Equivalence from the C# compiler perspective (and promises that more is to come)</P>]]></content:encoded>
    </item>
    <item>
      <title>VS 2010 compiler error: Interop type XXX cannot be embedded. Use the applicable interface instead.</title>
      <link>https://docs.microsoft.com/archive/blogs/mshneer/vs-2010-compiler-error-interop-type-xxx-cannot-be-embedded-use-the-applicable-interface-instead</link>
      <pubDate>Mon, 07 Dec 2009 11:26:00 GMT</pubDate>
      <dc:creator><![CDATA[Misha Shneerson - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mshneer/2009/12/07/vs-2010-compiler-error-interop-type-xxx-cannot-be-embedded-use-the-applicable-interface-instead/</guid>
      <description><![CDATA[Some users have reported that when using Visual Studio 2010 and referencing an Interop Assembly with...]]></description>
      <content:encoded><![CDATA[<P>Some users <A href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=508465" mce_href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=508465">have reported</A> that when using Visual Studio 2010 and referencing an Interop Assembly with "Embed Interop Types" set to TRUE they would get the error literally saying that the type cannot be embedded. Then the error would advise to use an interface - but w/o many additional details on where to get this interface from. This post is intended to explain the error and give an easy guidance on what the interface is.</P>
<P>One of the limitations for 'Embed Interop Types' feature has been that classes cannot be used when embedding an assembly. This limitation has to do with servicing - it is safe to embed metadata but not anything that can potentially contain executable code (class types&nbsp;contain metadata AND code while interfaces only contain metadata). When you try to references a class type from an Interop Assembly for which the "Embed Interop Types" is set to TRUE compiler do issue a warning. But in most cases you do not need to use classes from interop assemblies and minor code tweaking is needed to successfully compile with EIT=true.</P>
<P>Let's address the most common case of this error first.I will also address the cases when the user code uses constants from VSIP assemblies such as EnvDTE.Constants / VSLangProj.PrjKind below...</P>
<P>In most cases (such as error for the usage of UPnPNATClass as noted in one of the comments) this error is the result of code which tries to instantiate a COM object e.g. here piece of code starting up Excel:</P><FONT size=2 face=Consolas><FONT size=2 face=Consolas><FONT size=2 face=Consolas><FONT size=2 face=Consolas>
<P>Excel.</FONT></FONT><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas>ApplicationClass</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> xlapp = </FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>new</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> Excel.</FONT></FONT><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas>ApplicationClass</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas>();</P>
<P></FONT></FONT></FONT></FONT>Here it is enough to say that Excel.ApplicationClass derives from Excel.Application interface and one can even instantiate Excel using Excel.Application interface. Rewriting this code as below produces exact same results:</P><FONT size=2 face=Consolas><FONT size=2 face=Consolas>
<P>Excel.</FONT></FONT><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas>Application</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> xlapp = </FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>new</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> Excel.</FONT></FONT><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas>Application</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas>();</P></FONT></FONT>
<P>Typically, to&nbsp;change your code&nbsp;to use&nbsp;an interface type instead of a class type you just need to remove the 'Class' suffix and compile the code! Another way to find what the applicable interface is - look at the definition of the class type. The class usually derives from one or more interfaces.&nbsp;Look at the definition of each interface - one of them will have <STRONG>CoClass </STRONG>attribute&nbsp;and this is the interface that you are looking for.</P>
<P>The case with EnvDTE/VSLangProj is a little bit different. I believe there should be a recommendation coming from the VSIP team encouraging to use Type Embedding. Unfortunately, some constants in the EnvDTE/VSLangProj &nbsp;assemblies cannot be embedded. For these you will need manually embed the values of the constant into your project.Since those are constant fields in the abstract classes and should never change - this is a safe thing to do.</P>
<P>In the IDE you can right click on the value you need to embed, then copy&amp;paste the values locally. </P>
<P><BR>For example, suppose my C# code has code like this:</P><FONT size=2 face=Consolas><FONT size=2 face=Consolas>
<P>System.Windows.Forms.</FONT></FONT><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas>MessageBox</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas>.Show(EnvDTE.</FONT></FONT><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas>Constants</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas>.vsDocumentKindText);</P>
<P></FONT></FONT>When this code is compiled I will get compilation errors:<BR>&lt;errors&gt;<BR><EM>'EnvDTE.Constants' does not contain a definition for 'vsDocumentKindText'<BR>Interop type 'EnvDTE.Constants' cannot be embedded. Use the applicable interface instead.<BR></EM>&lt;/errors&gt;</P>
<P>In the IDE I will right click on vsDocumentKindText and choose "Go To Definition". This will take me what appears to be the definition of the constants class. I will copy the following lines and paste it in my code:<BR><FONT size=2 face=Consolas><FONT size=2 face=Consolas></P>
<P></FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>public</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> </FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>abstract</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> </FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>class</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> </FONT></FONT><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas>Constants<BR></FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas>{<BR></FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>&nbsp;&nbsp;&nbsp;&nbsp; public</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> </FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>const</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> </FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>string</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> vsDocumentKindText = </FONT></FONT><FONT color=#a31515 size=2 face=Consolas><FONT color=#a31515 size=2 face=Consolas><FONT color=#a31515 size=2 face=Consolas>"{8E7B96A8-E33D-11D0-A6D5-00C04FB67F6A}"</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas>;<BR>}</P></FONT></FONT>
<P>Then I will make the Constants class 'internal', rename the class to EnvDTEConstants. <FONT size=2 face=Consolas><FONT size=2 face=Consolas></P>
<P></FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>internal</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> </FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>abstract</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> </FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>class</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> </FONT></FONT><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas>EnvDTEConstants<BR></FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas>{<BR></FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>&nbsp;&nbsp;&nbsp; public</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> </FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>const</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> </FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>string</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> vsDocumentKindText = </FONT></FONT><FONT color=#a31515 size=2 face=Consolas><FONT color=#a31515 size=2 face=Consolas><FONT color=#a31515 size=2 face=Consolas>"{8E7B96A8-E33D-11D0-A6D5-00C04FB67F6A}"</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas>;<BR>}</P>
<P></FONT></FONT>Next, I will go through my code and change all the&nbsp;occurrences of EnvDTE.Constants to EnvDTEConstants. And now&nbsp;my code does compile!<BR><BR><FONT size=2 face=Consolas><FONT size=2 face=Consolas>System.Windows.Forms.</FONT></FONT><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas>MessageBox</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas>.Show(</FONT></FONT><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas>EnvDTEConstants</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas>.vsDocumentKindText);</P></FONT></FONT>]]></content:encoded>
    </item>
    <item>
      <title>Type Equivalence and Type Safety</title>
      <link>https://docs.microsoft.com/archive/blogs/mshneer/type-equivalence-and-type-safety</link>
      <pubDate>Mon, 03 Nov 2008 13:49:37 GMT</pubDate>
      <dc:creator><![CDATA[Misha Shneerson - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mshneer/2008/11/03/type-equivalence-and-type-safety/</guid>
      <description><![CDATA[What one should do on a plane back from the PDC? Of course! Write a new blog post! So, since I still...]]></description>
      <content:encoded><![CDATA[<p>What one should do on a plane back from the PDC? Of course! Write a new blog post! So, since I still have some topics to cover on the whole NOPIA shabang - here we go.</p>  <p>CLR’s 4.0 support for Type Equivalence allows you to define your own copy of an interface, stick a Guid on it and then you will be able to cast from any managed object implementing an interface with the same Guid. When calling a method on such interface CLR will find the equivalent interface in the inheritance chain of the managed object, verify you are not calling beyond the allowed vtable, verify that the signature at the same vtable offset does match and then call the corresponding method implementation.</p>  <p>This is all good and well and allows for loose type coupling, version resiliency and possibly some other goodness we have not found a name for yet but I have been repeatedly asked whether such arbitrary deviation from the fundamental .NET type system principals is type safe and whether FullTrust is required to make calls through equivalent type to work. Let’s address these concerns one by one. </p>  <p>I believe the mechanism is actually Type Safe . To try and illustrate my point I would make a fundamental assumption that calls through reflection are Type Safe. Most of you would probably agree. The way reflection mechanism works is it first verifies that parameters passed to the call can be cast to the parameter types specified by the method signature. If types do no match – reflection does not let the call to execute. Now compare this mechanism to the way calls for Type Equivalent interfaces are dispatched and try to find a difference :)</p>  <p>Now to the question of FullTrust. Let’s reuse the analogy with reflection once again and recall that reflection does not require FullTrust. Consequently, we can conclude that one is not needed for calls through Type Equivalent interface. The only exception to the rule is when the call contains Type Equivalent structures. Again, in theory, if we can prove that two struct types that are declared to be type equivalent are also structurally equivalent – we should not require FullTrust. The problem is that proving this might be more complicated than it seems to be (this is what I ‘ve been told) so this is too early to talk about what final bits will look like.</p>]]></content:encoded>
    </item>
    <item>
      <title>Face made for emails</title>
      <link>https://docs.microsoft.com/archive/blogs/mshneer/face-made-for-emails</link>
      <pubDate>Wed, 29 Oct 2008 17:17:00 GMT</pubDate>
      <dc:creator><![CDATA[Misha Shneerson - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mshneer/2008/10/29/face-made-for-emails/</guid>
      <description><![CDATA[Today I got a word that the video recordings I’ve made with Amanda Silver on the topics of Type...]]></description>
      <content:encoded><![CDATA[<P>Today I got a word that the video recordings I’ve made with Amanda Silver on the topics of Type Embedding and Type Equivalence did get published. My face is clearly should have been shaded out – but Amanda looks fantastic! Anyway, may be you will find this videos interesting. They are in the MP4 format so you need to have the corresponding player installed. Or see the below embedded player.</P>
<P><A href="https://www.informit.com/podcasts/episode.aspx?e=c7e5b7b2-516f-48cd-9cce-286f859bb687" mce_href="https://www.informit.com/podcasts/episode.aspx?e=c7e5b7b2-516f-48cd-9cce-286f859bb687">No PIAs: The Problems with Primary Interop Assemblies (PIA) - Part 1 of 4 (video)</A></P>
<P><A href="https://www.informit.com/podcasts/episode.aspx?e=731e3e23-3a65-4feb-80ba-c3de9275bd10" mce_href="https://www.informit.com/podcasts/episode.aspx?e=731e3e23-3a65-4feb-80ba-c3de9275bd10">No PIAs: Under The Hood - Part 2 of 4 (video)</A></P>
<P><A href="https://www.informit.com/podcasts/episode.aspx?e=1b3da26c-ccd0-4788-abd1-74c6a386636f" mce_href="https://www.informit.com/podcasts/episode.aspx?e=1b3da26c-ccd0-4788-abd1-74c6a386636f">No PIAs: Type Equivalence - Part 3 of 4 (video)</A></P>
<P><A href="https://www.informit.com/podcasts/episode.aspx?e=df0c5257-1e79-4d91-9fff-7180ee645779" mce_href="https://www.informit.com/podcasts/episode.aspx?e=df0c5257-1e79-4d91-9fff-7180ee645779">No PIAs: Versioning Object Models - Part 4 of 4 (video)</A></P>
<P>Also check out the entire library of other people from Microsoft that were recorded just before the PDC. To see the list of episodes click the multiple windows icon.&nbsp;</P>
<P>
<OBJECT id=PodangoPlayer height=240 width=320 align=middle><PARAM NAME="allowScriptAccess" VALUE="sameDomain"><PARAM NAME="allowFullScreen" VALUE="true"><PARAM NAME="movie" VALUE="https://www.podango.com/flash/player.swf?type=1&amp;id=2415&amp;color=2646311&amp;links="><PARAM NAME="quality" VALUE="high"><PARAM NAME="bgcolor" VALUE="#000000">
<embed src="https://www.podango.com/flash/player.swf?type=1&amp;id=2415&amp;color=2646311&amp;links=" mce_src="https://www.podango.com/flash/player.swf?type=1&amp;id=2415&amp;color=2646311&amp;links=" quality="high" bgcolor="#000000" width="320" height="240" name="PodangoPlayer" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer"></embed></OBJECT></P>]]></content:encoded>
    </item>
    <item>
      <title>Better eventing support in CLR 4.0 using NOPIA support</title>
      <link>https://docs.microsoft.com/archive/blogs/mshneer/better-eventing-support-in-clr-4-0-using-nopia-support</link>
      <pubDate>Tue, 28 Oct 2008 20:50:00 GMT</pubDate>
      <dc:creator><![CDATA[Misha Shneerson - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mshneer/2008/10/28/better-eventing-support-in-clr-4-0-using-nopia-support/</guid>
      <description><![CDATA[Events implementation in the Interop Assemblies does have its shortcomings. I enumerated the issues...]]></description>
      <content:encoded><![CDATA[<P>Events implementation in the Interop Assemblies does have its shortcomings. I enumerated the issues in “<A href="https://blogs.msdn.com/mshneer/archive/2008/10/18/com-interop-handling-events-has-side-effects.aspx" mce_href="https://blogs.msdn.com/mshneer/archive/2008/10/18/com-interop-handling-events-has-side-effects.aspx">COM Interop: Handling events has side effects</A>” post. The quick recap is that Interop Assemblies eventing support does create “ghost RCWs” that get in the way of deterministically managing the life-time of your COM objects. </P>
<P>But there is a hope! The Type Embedding work that we are doing for NOPIA feature eliminates the dependency on Interop Assemblies by embedding the partial local copies of Interop interfaces into the assembly that uses those interfaces. </P>
<P>This customized compiler behavior for Interop Types has been a great opportunity for us to fix the way COM events are handled. Since the implementation of the event sink is currently located in the Interop Assemblies in the pure IL – and the design decision behind types embedding is that we never copy IL – we needed to come up with a different mechanism.</P>
<P>So, we taught the compiler to recognize code patterns that subscribe to events for Interop Assembly types and replace this pattern with something else. To give you an example from my PDC Type Embedding demo – here is the code that subscribes to SheetSelectionChange event from Excel’s Applcation object.</P><PRE class=code>xlapp.SheetSelectionChange += xlapp_SheetSelectionChange;</PRE>
<P>The code that is emitted by the compiler is very different though and it looks like this (I copied the below line from Reflector’s Disassembler window):</P>
<P>ComEventsHelper.Combine(xlapp, new Guid("00024413-0000-0000-C000-000000000046"), 0x616, new AppEvents_SheetSelectionChangeEventHandler(Program.xlapp_SheetSelectionChange));</P>
<P>You can probably figure out some of the parameters to ComEventsHelper.Combine API i.e. xlapp and the delegate are self-describing. But the reason for the existence of the Guid and the mysterious integer 0x616 may not be immediately apparent. So, what is going on here? </P>
<P>When compilers encounter code that subscribes to an event on an interface coming from Interop Assembly they are trying to analyze how this event is exposed by the COM object. In particular, they need to find the interface COM object would call on when raising the event. So they look in the PIA and end up finding the AppEvents interface which is declared like this:</P>
<P>[<SPAN style="COLOR: #2b91af">Guid</SPAN>(<SPAN style="COLOR: #a31515">"00024413-0000-0000-C000-000000000046"</SPAN>)] <BR><SPAN style="COLOR: blue">public interface </SPAN><SPAN style="COLOR: #2b91af">AppEvents <BR></SPAN>{ <BR>&nbsp;&nbsp;&nbsp; [<SPAN style="COLOR: #2b91af">DispId</SPAN>(2612)] <BR>&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">void </SPAN>AfterCalculate(); <BR>&nbsp;&nbsp;&nbsp; [<SPAN style="COLOR: #2b91af">DispId</SPAN>(1558)] <BR>&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">void </SPAN>SheetSelectionChange(<SPAN style="COLOR: blue">object </SPAN>Sh, <SPAN style="COLOR: #2b91af">Range </SPAN>Target); <BR>&nbsp;&nbsp;&nbsp; [<SPAN style="COLOR: #2b91af">DispId</SPAN>(1556)] <BR>&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">void </SPAN>WindowActivate(<SPAN style="COLOR: #2b91af">Workbook </SPAN>Wb, <SPAN style="COLOR: #2b91af">Window </SPAN>Wn);</P>
<P>…. <BR>}</P>
<P>Look at the Guid on this interface – this is the same Guid passed to ComEventsHelper.Combine API. </P>
<P>Also, if you have no problem translating between decimal and hexadecimal you have already realized that 1558=0x616 (I personally used calc.exe to do translation).</P>
<P>So, Combine API attaches an event sink to the COM object’s connection point that handles invocation on the interface with specified GUID. It also tells the event sink that when a method with dispid==0x616 is called it should invoke the delegate that is passed as the last parameter. </P>
<P>Important thing about the event sink is:</P>
<OL>
<LI>It is implemented using unsafe managed code</LI>
<LI>It responds to QIs for the above GUID&nbsp; using the new ICustomQueryInterface which allows managed objects to customize their IUnknown.QueryInterface behavior </LI>
<LI>It only handles late-bound invocation on the source interface. Generally, this should not be a big problem since almost all the COM applications use late-binding when raising events.</LI>
<LI>Subsequent calls to ComEventsHelper.Combine for the same COM object will re-use the existing sink – resulting that there always is only one interop transition when managed code registers multiple event handles</LI>
<LI>The event sink does not marshal parameters to the call if there is no user delegate register against a particular dispid. This solves the problem of the “ghost RCWs”</LI>
<LI>There is a corresponding ComEventHelpers.Remove API which allows to remove the event handler </LI></OL>
<P>So, effectively if you compile your code with NOPIAs – the problems I previously raised with the way events are handled by Interop Assemblies should go away!</P>
<P>I am also attaching the source of the simple demo that demonstrates Type Equivalence. You will need to download the Dev10 CTP here to run it - <A href="https://go.microsoft.com/fwlink/?LinkId=129231" mce_href="https://go.microsoft.com/fwlink/?LinkId=129231">https://go.microsoft.com/fwlink/?LinkId=129231</A></P>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/09/02/13/01/TypeEmbeddingDemo.zip" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-09-02-13-01/TypeEmbeddingDemo.zip">TypeEmbeddingDemo.zip</a></p>]]></content:encoded>
    </item>
  </channel>
</rss>