{"id":1561,"date":"2015-10-21T23:41:08","date_gmt":"2015-10-21T21:41:08","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=1561"},"modified":"2015-10-21T23:41:08","modified_gmt":"2015-10-21T21:41:08","slug":"registration-free-com-dependencies-and-com-reference-isolation","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/1561","title":{"rendered":"Registration-Free COM dependencies and COM reference isolation"},"content":{"rendered":"<p>Visual Studio offers COM reference isolation to applications so that COM dependency is used in a usual way, and in the same time there is no need in its registration or another copy of the COM server might be registered system wide, or using per-user registration, and the application would still prefer a local copy of COM server.<\/p>\n<p><a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Clipbrd5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1562\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Clipbrd5.png\" alt=\"Isolated Property\" width=\"708\" height=\"542\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Clipbrd5.png 708w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Clipbrd5-320x245.png 320w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Clipbrd5-624x478.png 624w\" sizes=\"auto, (max-width: 708px) 100vw, 708px\" \/><\/a><\/p>\n<p>The advantage is obvious: no more COM registration hell, and the application can be distributed with lowered risk of conflicts with other installed software, without a risk to affect other applications by registering an unwanted piece of software. Also, with an option to use COM dependency without need of elevated privileges to perform COM registration.<\/p>\n<p>The feature is using reg-free COM and is not new. Articles on internet on using the feature date back to 2007 and earlier (e.g. <a href=\"http:\/\/qualapps.blogspot.com\/2007\/06\/isolated-com.html\">Isolated COM<\/a>), reg-free COM existed earlier. The feature is cool and offers a one click access to an incredibly powerful option with complicated technology underneath.<\/p>\n<p><span style=\"text-decoration: underline;\">Problem 1<\/span>: It is 2015 fall today and Visual Studio 2013 still does not have this &#8211; as complicated as Enabled\/Disabled option &#8211; working right.<\/p>\n<p>Once enabled, the option has the following effect on the project:<\/p>\n<ol>\n<li>the manifest file is detached from the binary and is written to external file (Client.exe + Client.exe.manifest as opposed to Client.exe with manifest embedded as resource)<\/li>\n<li>the manifest receives assembly\/file elements that establish a registration-free link to COM dependency; the content of the element is repeating registration of the COM dependency normally written into registry system wide<\/li>\n<li>the compiler uses <code><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms724901\">RegOverridePredefKey<\/a><\/code> and friends API to check COM dependency registration keys and update the manifest file (see previous item) respectively<\/li>\n<\/ol>\n<p>Apparently the COM server has to be registered at compile time, so that compiler could convert the registration into manifest file. For whatever reason, Visual Studio 2013 looks for 32-bit COM server when it is doing 64-bit build. That is, building x64 configuration with x64 COM server registered and supposed to be used further fails if you don&#8217;t have a similar Win32 COM server registered. Bummer.<\/p>\n<p>This simple solution <code>ComIsolation01<\/code> (<a href=\"https:\/\/www.alax.info\/trac\/public\/browser\/trunk\/Utilities\/Miscellaneous\/ComIsolation01\/\">Trac<\/a>, <a href=\"https:\/\/www.alax.info\/svn\/public\/trunk\/Utilities\/Miscellaneous\/ComIsolation01\/\">SVN<\/a>) has two projects: C++ COM server with 32 and 64 bit configurations, and C# client consumer. A build of Debug\/Release x64 configuration successfully builds Server.dll, registers it, then attempts to build Client.exe and fails:<\/p>\n<blockquote><p>2&gt;C:\\Program Files (x86)\\MSBuild\\12.0\\bin\\Microsoft.Common.CurrentVersion.targets(2234,5): warning MSB3284: Cannot get the file path for type library &#8220;ae2714e3-e8be-44c7-b737-5510e5f8abed&#8221; version 1.0. Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_<em>E_<\/em>LIBNOTREGISTERED))<br \/>\n2&gt;D:\\Projects\\Alax.Info\\Repository-Public\\Utilities\\Miscellaneous\\ComIsolation01\\Client\\Program.cs(14,13,14,22): error CS0246: The type or namespace name &#8216;ServerLib&#8217; could not be found (are you missing a using directive or an assembly reference?)<br \/>\n2&gt;D:\\Projects\\Alax.Info\\Repository-Public\\Utilities\\Miscellaneous\\ComIsolation01\\Client\\Program.cs(14,51,14,60): error CS0246: The type or namespace name &#8216;ServerLib&#8217; could not be found (are you missing a using directive or an assembly reference?)<\/p><\/blockquote>\n<p><code>TYPE_E_LIBNOTREGISTERED<\/code>, really? Because it looks for 32-bit type library and there is only 64-bit one registered. Build Win32 configuration once, and x64 builds are fixed. In other aspects, x64 build of Server.dll is correctly picked up.<\/p>\n<p><span style=\"text-decoration: underline;\">Problem 2<\/span>: Inflexible. The only COM reference isolation offered is a link with size and hash specification of the dependency.<\/p>\n<p><a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Clipbrd6.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1563\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Clipbrd6-800x245.png\" alt=\"Strict dependency check in manifest file\" width=\"625\" height=\"191\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Clipbrd6-800x245.png 800w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Clipbrd6-320x98.png 320w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Clipbrd6-624x191.png 624w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2015\/10\/Clipbrd6.png 1170w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><\/p>\n<p>Why on earth? Okay it might be good for some people, perhaps. The only scenario I want to ever use is a link without checks for whether dependency is exactly as at build time. It is already isolated and the isolated file will be picked up. I would like to retain an option to patch it quickly by simply substituting a new file there, without an annoying need to patch manifest respectively. I don&#8217;t have an option like this.<\/p>\n<p>Another post soon will show a solution for the problem, as well as easy way to apply isolation to C++ clients as well.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Visual Studio offers COM reference isolation to applications so that COM dependency is used in a usual way, and in the same time there is no need in its registration or another copy of the COM server might be registered system wide, or using per-user registration, and the application would still prefer a local copy&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/1561\">Read the full article<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[95,497,498,496,70],"class_list":["post-1561","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-com","tag-isolation","tag-manifest","tag-regfree","tag-winapi"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1561","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=1561"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1561\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=1561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=1561"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=1561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}