Reference to SharePoint API from a visual studio web project on an x64 environment

Could not load file or assembly 'Microsoft.SharePoint.Search, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. An attempt was made to load a program with an incorrect format.

I endedup with this message when I opened a web project under visual studio after referencing the Microsoft.SharePoint assembly.

What happend is that I'm actually using a x64 environment (in my case WIN2008 x64 & MOSS x64) and the Microsoft.SharePoint.Search assembly is compiled for AMD64 in my GAC where the process is searching for a x86 version of this assembly.

Solution found: Copy the x86 version of the file in the GAC (both versions can reside side by side without conflicting). You can find this file under "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI".