<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Do not write in-process shell extensions in managed code</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/12/18/1317290.aspx</link><description>It creates a version conflict.</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>Property Handler Decisions and Preparation</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/12/18/1317290.aspx#1555584</link><pubDate>Tue, 30 Jan 2007 09:47:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1555584</guid><dc:creator>The Great Flying Tortoise</dc:creator><description>&lt;p&gt;Viewed as a data flow component, a property handler has a single file stream input and outputs a one&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1555584" width="1" height="1"&gt;</description></item><item><title>re: Do not write in-process shell extensions in managed code</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/12/18/1317290.aspx#1345092</link><pubDate>Fri, 22 Dec 2006 08:20:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1345092</guid><dc:creator>Dean Harding</dc:creator><description>&lt;p&gt;&amp;gt; Office components always run out-of-process when started through COM, so it's not an issue in that case.&lt;/p&gt;
&lt;p&gt;Are you sure about that? I use both Lookout and Newgator in Outlook, both of which are .NET add-ins and both of which run in-process. Perhaps they don't use VSTO, though...&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1345092" width="1" height="1"&gt;</description></item><item><title>re: Do not write in-process shell extensions in managed code</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/12/18/1317290.aspx#1341269</link><pubDate>Thu, 21 Dec 2006 20:28:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1341269</guid><dc:creator>AndyB</dc:creator><description>&lt;p&gt;&amp;gt; To everyone else: don't mix .NET and native code, it's a terrible practice&lt;/p&gt;
&lt;p&gt;I thought it just works.&lt;/p&gt;
&lt;p&gt;&amp;gt; Native code rarely owns a whole process&lt;/p&gt;
&lt;p&gt;Really? I wonder what all these exe's I've been writing for years are.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1341269" width="1" height="1"&gt;</description></item><item><title>re: Do not write in-process shell extensions in managed code</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/12/18/1317290.aspx#1339834</link><pubDate>Thu, 21 Dec 2006 15:02:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1339834</guid><dc:creator>KJK::Hyperion</dc:creator><description>&lt;p&gt;Eric, Dean: Office components always run out-of-process when started through COM, so it's not an issue in that case&lt;/p&gt;
&lt;p&gt;Daniel, Cooney: I'm always surprised at the lengths people will go to try and contradict Microsoft's design choices, often apparently for the heck of it. The &amp;quot;try to fix this Windows bug&amp;quot; challenge was especially eye-opening&lt;/p&gt;
&lt;p&gt;To everyone else: don't mix .NET and native code, it's a terrible practice. Do it only if forced to do so, but don't incorporate it in an architecture developed from scratch&lt;/p&gt;
&lt;p&gt;It's inefficient and terribly embarassing to the runtime, which never has the slightest idea how to handle native calls - will it corrupt the managed heap? will it close one of my internal handles? will it violate security policies? etc. Internal framework functions are not P/Invoke, for a good reason - their C++ implementations are so filled with static code checking annotations (pssst, .NET sources are public) as to virtually offer the same guarantees as managed code&lt;/p&gt;
&lt;p&gt;Nevertheless, if you absolutely have to, make it so managed calls native and not the other way around. Native code rarely owns a whole process (notable exceptions are DBMSs, in fact .NET 2.0 was specifically tuned to be hosted by SQL Server) the way a runtime does, so despite the huge inefficiency it's not quite as dramatic as pulling the runtime in a random process&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1339834" width="1" height="1"&gt;</description></item><item><title>re: Do not write in-process shell extensions in managed code</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/12/18/1317290.aspx#1333779</link><pubDate>Thu, 21 Dec 2006 01:37:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1333779</guid><dc:creator>Dean Harding</dc:creator><description>&lt;p&gt;Eric: Office add-ins are a little different. The problem with explorer extensions is that your extension gets injected into every other process that tries to open a file-open dialog (or other things). Office add-ins are only run in the Office executable (well, usually - I'm not sure what happens with OLE in this case).&lt;/p&gt;
&lt;p&gt;When you call a CCW (that is, a .NET object implementing a COM interface) from a native application, the infrastructure (by default) loads the most recent version of framework that's installed. So Office will typically be running .NET 2.0. This is not a problem for most .NET 1.1 add-ins, which will mostly run quite happily under .NET 2.0.&lt;/p&gt;
&lt;p&gt;With explorer, it doesn't always work like that. If you have a process that has ALREADY loaded the 1.1 framework, then it tries to open a file-open dialog and load your .NET 2.0 extension... bang!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1333779" width="1" height="1"&gt;</description></item><item><title>re: Do not write in-process shell extensions in managed code</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/12/18/1317290.aspx#1332407</link><pubDate>Wed, 20 Dec 2006 20:15:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1332407</guid><dc:creator>Eric Smith</dc:creator><description>&lt;p&gt;What about Office add-ins?&lt;/p&gt;
&lt;p&gt;I'm having trouble reconciling the discussion here with the apparent encouragement to write managed add-ins for Office represented by the existence of VSTO. Doesn't the same problem exist there (although without the file dialog issue)? Is VSTO only practical in completely controlled environments where all add-ins are guaranteed to use the same CLR?&lt;/p&gt;
&lt;p&gt;Sorry, I know this is straying off-topic for Raymond's expertise; you've got a knowledgable community here, though. &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1332407" width="1" height="1"&gt;</description></item><item><title>re: Do not write in-process shell extensions in managed code</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/12/18/1317290.aspx#1328757</link><pubDate>Wed, 20 Dec 2006 11:26:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1328757</guid><dc:creator>Random Reader</dc:creator><description>&lt;p&gt;Gabe,&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt; The CLR will only know that your main assembly is asking for a class called &amp;quot;FtpRequest&amp;quot;. Since this putative app is not directly referencing Foo.FtpRequest, the CLR will look for FtpRequest and its own version first.&lt;/p&gt;
&lt;p&gt;That's what I'm saying is incorrect: if your app's assembly name is Foo (normally filenamed Foo.exe as well, but that isn't relevant), all references to FtpRequest will in fact be to FtpRequest _in assembly Foo_.&lt;/p&gt;
&lt;p&gt;Explicit namespaces are necessary for organizational reasons, but not for type resolution.&lt;/p&gt;
&lt;p&gt;This is the same concept as for native executables: the PE import table references a specific DLL, not just a symbol from anywhere at random.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1328757" width="1" height="1"&gt;</description></item><item><title>re: Do not write in-process shell extensions in managed code</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/12/18/1317290.aspx#1328514</link><pubDate>Wed, 20 Dec 2006 08:56:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1328514</guid><dc:creator>John Stewien</dc:creator><description>&lt;p&gt;Gabe,&lt;/p&gt;
&lt;p&gt;shouldn't people be using signed assemblies on released products, and thus not have this problem?&lt;/p&gt;
&lt;p&gt;Also isn't the take home message of all this &amp;quot;Don't use managed code in shell extensions&amp;quot;? Managed code should just be used for fancy GUI stuff and web apps surely. Is C/C++ really that hard? It's all I used up until 5 years ago.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1328514" width="1" height="1"&gt;</description></item><item><title>re: Do not write in-process shell extensions in managed code</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/12/18/1317290.aspx#1328399</link><pubDate>Wed, 20 Dec 2006 08:15:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1328399</guid><dc:creator>Gabe</dc:creator><description>&lt;p&gt;RandomReader, here's what I said &amp;quot;Of course you could just put the class in a namespace (like you should have done in the first place) and recompile, but your customers can't recompile.&amp;quot;&lt;/p&gt;
&lt;p&gt;The CLR will only know that your main assembly is asking for a class called &amp;quot;FtpRequest&amp;quot;. Since this putative app is not directly referencing Foo.FtpRequest, the CLR will look for FtpRequest and its own version first.&lt;/p&gt;
&lt;p&gt;Like I said, there are trivial steps to take ahead of time (strong names, namespaces, etc.). If you didn't do this when compiling your apps the first time, though, you're in trouble if your client only has the old version of the app and the new version of the CLR.&lt;/p&gt;
&lt;p&gt;In the case of a shell extension, you don't get to choose which version of the CLR to load, the app or the first managed shell extension does. The only way to guarantee it working in this case is to send out a recompiled version using properly bound names.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1328399" width="1" height="1"&gt;</description></item><item><title>re: Do not write in-process shell extensions in managed code</title><link>http://blogs.msdn.com/b/oldnewthing/archive/2006/12/18/1317290.aspx#1327846</link><pubDate>Wed, 20 Dec 2006 05:50:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1327846</guid><dc:creator>Random Reader</dc:creator><description>&lt;p&gt;Gabe,&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt; For example, let's say you have a CLR 1.1 shell extension Foo that does FTP, and is has a class called FtpRequest. When you run it on CLR 1.2 which implements its own FtpRequest class, Foo stops working because it gets the CLR's FtpRequest instead of your own.&lt;/p&gt;
&lt;p&gt;The class name resolution rules, at minimum, also include a reference the containing assembly. &amp;nbsp;The CLR knows FtpRequest in your assembly is not the same class as FtpRequest in any other assembly, so this situation cannot occur.&lt;/p&gt;
&lt;p&gt;Michiel,&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt; The root question is: why is the CLR linked against the managed executable using what is in effect a process-wide namespace? Because if multiple CLRs could co-exist, an extension needing CLR 1.0 would link against that CLR, and another could link against CLR 2.0. That doesn't sound hard: if an managed app wants symbols from CLR 1.0, in the compiler simply prefix every symbol with __CLR10__. If from 1.1, __CLR11__.&lt;/p&gt;
&lt;p&gt;The CLR is not a library that is linked to an executable; it is a runtime. &amp;nbsp;On newer versions of Windows, a flag in the managed .exe header instructs the OS loader to launch and initialize the CLR, which then loads and executes the managed code from the .exe. &amp;nbsp;(On older versions of Windows, a native-code shim in the .exe's entry point launches the CLR instead.)&lt;/p&gt;
&lt;p&gt;Because it is a full runtime, which manages detailed characteristics of the low-level process environment, it is not possible for it to play well with any other code that wishes to do the same thing. &amp;nbsp;Consider the Garbage Collector, which needs to understand memory usage in the process, in order to correctly self-tune. &amp;nbsp;Two such GCs would end up fighting each other, much as two processes that try to efficiently use all available RAM on a server would behave. &amp;nbsp;(There's an old blog post somewhere about, IIRC, IIS and SQL Server that describes a similar case.)&lt;/p&gt;
&lt;p&gt;Or for something more high-level, consider the WinForms part of the Framework. &amp;nbsp;Naturally it requires a message loop for a managed thread, and there can be only one main message loop (broadcasts, non-window messages, etc). &amp;nbsp;How are WinForms 1.x and 2.x supposed to both have a main message loop at the same time on the same thread?&lt;/p&gt;
&lt;p&gt;So it's not just a simple symbol naming issue :)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1327846" width="1" height="1"&gt;</description></item></channel></rss>