I no longer work at Microsoft, so please don't bother leaving a comment here or trying to contact me through my MSDN blog.
You can find my new blog at http://www.technologytoolbox.com/blog/jjameson. My new site also provides copies of all posts from my MSDN blog.
I encountered a rather nasty bug last week with Microsoft Office SharePoint Server (MOSS) 2007 when trying to run an x86 process (that utilizes the SharePoint API) on an x64 server.
To provide the simplest repro possible, I created a sample console application that prints the title of a SharePoint site:
using System; using Microsoft.SharePoint; namespace Fabrikam.Demo.PrintSharePointSiteTitle { class Program { static void Main( string[] args) { if (args.Length < 1) { Console.Error.WriteLine( "Usage: PrintSharePointSiteTitle {site URL}"); Environment.Exit(1); } string siteUrl = args[0]; using (SPSite site = new SPSite(siteUrl)) { Console.WriteLine( "Title: {0}", site.RootWeb.Title); } } } }
Note that by default, Visual Studio projects set the platform target to Any CPU. Thus when you run this program on an x64 server, the process runs natively in 64-bit and everything works as expected:
However, if you change the platform target to x86 and thus force the process to run in 32-bit then things don't go well:
I could certainly understand getting a BadImageFormatException in this scenario (in other words, if the platform target for Microsoft.SharePoint.dll was set to x64, then you shouldn't expect to be able to load it from a 32-bit process). Instead I get a "bogus" FileNotFoundException suggesting my Web application doesn't exist.
BadImageFormatException
FileNotFoundException
At this point, you're probably thinking something like "Jeremy, why would you possibly want to run a 32-bit process on a 64-bit server?" Great question...
There are at least a couple of scenarios that I'm aware of:
It's the latter scenario in which I first encountered this bug. However, rather than going into the details here, I want to cover the ImportPages.exe utility in a separate post.