<?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>AnyCPU Exes are usually more trouble than they're worth</title><link>http://blogs.msdn.com/b/rmbyers/archive/2009/06/09/anycpu-exes-are-usually-more-trouble-then-they-re-worth.aspx</link><description>Over the past few months I've had some interesting debates with folks here (and some customers) about the cost/benefit trade-off of "AnyCPU" (architecture-neutral) managed EXEs. I think we've converged on a consensus that most of the time they're not</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: AnyCPU Exes are usually more trouble than they're worth</title><link>http://blogs.msdn.com/b/rmbyers/archive/2009/06/09/anycpu-exes-are-usually-more-trouble-then-they-re-worth.aspx#10085717</link><pubDate>Wed, 03 Nov 2010 21:26:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10085717</guid><dc:creator>Ethan</dc:creator><description>&lt;p&gt;This breaks SharePoint development, since all SharePoint 2010 bits are built 64bits. &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10085717" width="1" height="1"&gt;</description></item><item><title>re: AnyCPU Exes are usually more trouble than they're worth</title><link>http://blogs.msdn.com/b/rmbyers/archive/2009/06/09/anycpu-exes-are-usually-more-trouble-then-they-re-worth.aspx#10051381</link><pubDate>Wed, 18 Aug 2010 09:35:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10051381</guid><dc:creator>Simon Cooper</dc:creator><description>&lt;p&gt;For those interested, I&amp;#39;ve figured out how you can change it back - &lt;a rel="nofollow" target="_new" href="http://www.simple-talk.com/community/blogs/simonc/archive/2010/08/17/94124.aspx"&gt;www.simple-talk.com/.../94124.aspx&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10051381" width="1" height="1"&gt;</description></item><item><title>re: AnyCPU Exes are usually more trouble than they're worth</title><link>http://blogs.msdn.com/b/rmbyers/archive/2009/06/09/anycpu-exes-are-usually-more-trouble-then-they-re-worth.aspx#10050333</link><pubDate>Sun, 15 Aug 2010 23:40:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10050333</guid><dc:creator>Simon Waterer</dc:creator><description>&lt;p&gt;I&amp;#39;ll just share an issue I had upgrading a VS2008 project to VS2010 relating to AnyCPU exe&amp;#39;s and COM Interop assemblies.&lt;/p&gt;
&lt;p&gt;The project was created in VS2008 as an AnyCPU exe and referenced the &amp;quot;Windows Script Host Object Model&amp;quot; COM library, which causes the Interop.IWshRuntimeLibrary.dll assembly to be generated at compile time. With VS2008 all was well running on both x86 and x64 platforms.&lt;/p&gt;
&lt;p&gt;After upgrading the project to VS2010 the project appeared to remain targeted to the AnyCPU platform but it would encounter a BadImageFormatException when run on x64 platforms at the point of loading the Interop.IWshRuntimeLibrary.dll assembly. The exception did not occur on x86 platforms. &lt;/p&gt;
&lt;p&gt;I eventually tracked down the problem by creating a new project afresh in VS2010 and diffing the .csproj files until I found that the freshly created VS2010 project file had a &amp;lt;PlatformTarget&amp;gt;AnyCPU&amp;lt;/PlatformTarget&amp;gt; element present within the &amp;lt;PropertyGroup Condition=&amp;quot; &amp;#39;$(Configuration)|$(Platform)&amp;#39; == &amp;#39;Debug|AnyCPU&amp;#39; &amp;quot;&amp;gt;...&amp;lt;/PropertyGroup&amp;gt; and &amp;lt;PropertyGroup Condition=&amp;quot; &amp;#39;$(Configuration)|$(Platform)&amp;#39; == &amp;#39;Release|AnyCPU&amp;#39; &amp;quot;&amp;gt;...&amp;lt;/PropertyGroup&amp;gt; elements, whereas the project upgraded from VS2008 to VS2010 did not define the &amp;lt;PlatformTarget&amp;gt;AnyCPU&amp;lt;/PlatformTarget&amp;gt; element at all.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve been able to reproduce this issue several times, every time it appears that the VS2008 to VS2010 upgrade does not place the &amp;lt;PlatformTarget&amp;gt;AnyCPU&amp;lt;/PlatformTarget&amp;gt; element in the .csproj file. &lt;/p&gt;
&lt;p&gt;I&amp;#39;m guessing here that the BadImageFormatException arose because the C# compilation target in MSBuild uses the Platform property (which was correctly left at AnyCPU during the upgrade) as the platform target, whereas the COM reference generation target in MSBuild uses the PlatformTarget property, and since it was not defined after the upgrade it defaulted to x86. There was no problem earlier with VS2008 because it would have defaulted to AnyCPU.&lt;/p&gt;
&lt;p&gt;What misled me about this was that the VS2010 GUI was displaying Any CPU in the dropdown for Platform target under the project property pages. It wasn&amp;#39;t until I changed it to x86 or x64 (i.e. something other than Any CPU), saved the project, then changed it back to Any CPU, and saved the project again did the &amp;lt;PlatformTarget.../&amp;gt; element appear in the project file.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10050333" width="1" height="1"&gt;</description></item><item><title>re: AnyCPU Exes are usually more trouble than they're worth</title><link>http://blogs.msdn.com/b/rmbyers/archive/2009/06/09/anycpu-exes-are-usually-more-trouble-then-they-re-worth.aspx#10048634</link><pubDate>Wed, 11 Aug 2010 01:00:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10048634</guid><dc:creator>SamC</dc:creator><description>&lt;p&gt;I&amp;#39;m staggered at the attitude of &amp;quot;let&amp;#39;s not do anything&amp;quot;.&lt;/p&gt;
&lt;p&gt;1. Test and fix issues. Software always has bugs anyway. Test on a 64-bit platform. Everyone has one now.&lt;/p&gt;
&lt;p&gt;2. Who cares that you lose a few percent performance? &amp;gt; 2GB memory available for processes on 64-bit. More and more applications will NEED this.&lt;/p&gt;
&lt;p&gt;3. People like you are the REASON the tools haven&amp;#39;t been made yet. Microsoft are using YOUR BLOG as an example of reason to JUSTIFY not doing anything. See Microsoft Connect ID 431200.&lt;/p&gt;
&lt;p&gt;Your points are irrelevant to future (and some current) application requirements.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10048634" width="1" height="1"&gt;</description></item><item><title>re: AnyCPU Exes are usually more trouble than they're worth</title><link>http://blogs.msdn.com/b/rmbyers/archive/2009/06/09/anycpu-exes-are-usually-more-trouble-then-they-re-worth.aspx#10047233</link><pubDate>Fri, 06 Aug 2010 23:25:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10047233</guid><dc:creator>Rick Byers - exMSFT</dc:creator><description>&lt;p&gt;I should also add: I think a core part of the problem here is the diagnostics experience for BadFormatException. &amp;nbsp;Would it have helped if you got at least a more precise error message here? &amp;nbsp;Something like &amp;quot;BadFormatException: Attempt to load an x86-only DLL &amp;#39;path\foo.dll&amp;#39; into a 64-bit process&amp;quot;? &amp;nbsp;That would be a GREAT feature suggestion for the CLR, and I&amp;#39;d be happy to talk to some people here to see if we can get that done for CLR 4.5.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10047233" width="1" height="1"&gt;</description></item><item><title>re: AnyCPU Exes are usually more trouble than they're worth</title><link>http://blogs.msdn.com/b/rmbyers/archive/2009/06/09/anycpu-exes-are-usually-more-trouble-then-they-re-worth.aspx#10047229</link><pubDate>Fri, 06 Aug 2010 23:13:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10047229</guid><dc:creator>Rick Byers - exMSFT</dc:creator><description>&lt;p&gt;Jesper, I&amp;#39;m sorry to hear you&amp;#39;ve had this trouble. &amp;nbsp;Just to make sure I understand your scenario: you created an EXE project in VS2010 (which is set to x86), and then later changed it to a build as a class library instead, but didn&amp;#39;t realize that it was buiding as an x86-only class library? &amp;nbsp;I agree that&amp;#39;s a nasty trap to fall into - it would have been nice if we thought to add a warning in that case suggesting the user may want to change the platform as well.&lt;/p&gt;
&lt;p&gt;That said, this is far from an issue of &amp;quot;a product that crashes vs. Edit &amp;amp; Continue support&amp;quot;. &amp;nbsp;As I mention above, by far the strongest reason for this change is about reliability of testing and consistent behavior. &amp;nbsp;I&amp;#39;d bet you prefer having your applicaiton crash reliably and quickly whenever you test it on a 64-bit machine, then having one that seems to work OK but occasionaly causes weird problems for your customers on 64-bit machines. &amp;nbsp;The bottom line is that if you really want your application to switch automatically between running as a 32-bit and 64-bit process, that&amp;#39;s an important decision - and one we think you should make intentionally with knowledge of the implications it has for your testing and deployment.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10047229" width="1" height="1"&gt;</description></item><item><title>re: AnyCPU Exes are usually more trouble than they're worth</title><link>http://blogs.msdn.com/b/rmbyers/archive/2009/06/09/anycpu-exes-are-usually-more-trouble-then-they-re-worth.aspx#10047221</link><pubDate>Fri, 06 Aug 2010 22:48:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10047221</guid><dc:creator>Jesper</dc:creator><description>&lt;p&gt;why thank you. I just spent hours debugging a crash: a BadImageFormatException in kernelbase.dll apparently. Turns out to be because of your little shortcut to make Edit&amp;amp;Continue work by default on 64-bit machines. One of our libraries had been set to x86 because of it, and our Any CPU process running on a 64-bit machine apparently didn&amp;#39;t like that. Setting everything consistently to Any CPU fixed it.&lt;/p&gt;
&lt;p&gt;So, when changing this default, it didn&amp;#39;t occur to anyone that some users might not create every project anew in VS2k10, and let its output type stay fixed forever? People importing a project from VS2008 get a nice AnyCPU process. And if you dare change the output type of an executable project to Class Library, you get a x86 .dll. And if you try to load that into your AnyCPU process on a 64-bit machine, hilarity ensues.&lt;/p&gt;
&lt;p&gt;Yes, I can understand the thinking behind this decision, but it seems like no one spent as much as 5 minutes thinking about the negative consequences of this change. I don&amp;#39;t know about everyone else, but I prefer a product that doesn&amp;#39;t crash over Edit &amp;amp; Continue support.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10047221" width="1" height="1"&gt;</description></item><item><title>re: AnyCPU Exes are usually more trouble than they're worth</title><link>http://blogs.msdn.com/b/rmbyers/archive/2009/06/09/anycpu-exes-are-usually-more-trouble-then-they-re-worth.aspx#10019652</link><pubDate>Thu, 03 Jun 2010 19:54:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10019652</guid><dc:creator>Rick Byers - exMSFT</dc:creator><description>&lt;p&gt;Andreas,&lt;/p&gt;
&lt;p&gt;The EXE for the process must have the LARGEADDRESSAWARE bit set in it&amp;#39;s header. &amp;nbsp;If it&amp;#39;s a .NET EXE then you need to use the &amp;#39;editbin&amp;#39; tool after it&amp;#39;s created to set this bit (see &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/clr/thread/c50ea343-b41b-467d-a457-c5a735e4dfff/here"&gt;here&lt;/a&gt;). &amp;nbsp;Is seems the managed compilers have chosen not to make this an option due to concerns over some DLLs you may load that don&amp;#39;t support LAE (see &lt;a href="http://connect.microsoft.com/VisualStudio/feedback/details/93771/net-compilers-should-support-a-largeaddressaware-flaghere"&gt;here&lt;/a&gt;). &amp;nbsp;I&amp;#39;ve added these links and softened my guidance above to account for this. &amp;nbsp;Thanks for bringing this up.&lt;/p&gt;
&lt;p&gt;Rick&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10019652" width="1" height="1"&gt;</description></item><item><title>re: AnyCPU Exes are usually more trouble than they're worth</title><link>http://blogs.msdn.com/b/rmbyers/archive/2009/06/09/anycpu-exes-are-usually-more-trouble-then-they-re-worth.aspx#10019639</link><pubDate>Thu, 03 Jun 2010 19:26:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10019639</guid><dc:creator>Andreas M.</dc:creator><description>&lt;p&gt;Thank you for this detailed clarification on the subject. You say &amp;quot;The first thing that should usually be done to such programs is to have them opt-into 4GB mode so that they can get a full 4GB of address space when running in the WOW on a 64-bit OS&amp;quot;. Can you point me to an MSDN article or something that explains how this is to be done? Thanks in advance!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10019639" width="1" height="1"&gt;</description></item><item><title>re: AnyCPU Exes are usually more trouble than they're worth</title><link>http://blogs.msdn.com/b/rmbyers/archive/2009/06/09/anycpu-exes-are-usually-more-trouble-then-they-re-worth.aspx#10016534</link><pubDate>Thu, 27 May 2010 19:57:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10016534</guid><dc:creator>Rick Byers - exMSFT</dc:creator><description>&lt;p&gt;Thomas,&lt;/p&gt;
&lt;p&gt;DLLs produced by VS2010 are AnyCPU by default and so you shouldn&amp;#39;t have any trouble there. &amp;nbsp;EXEs are x86 by default and so won&amp;#39;t load for EXECUTION in a 64-bit process (eg. Assembly.Load/LoadFrom will fail). &amp;nbsp;But if you&amp;#39;re just loading an EXE for inspection purposes, Assembly.ReflectionOnlyLoad should be able to load it for you - even if it isn&amp;#39;t compatible with your processes bitness (and you should be using ReflectionOnlyLoad anyway if you don&amp;#39;t want to execute anything from the assembly).&lt;/p&gt;
&lt;p&gt;Hope this helps,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; Rick&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10016534" width="1" height="1"&gt;</description></item></channel></rss>