If you are using SharePoint Server 2007 to build a console application, you would do something like this:
If you take the same code, execute it against SharePoint 2010, you will be surprised (at least for the first time) to see VS2010 throw an error!
There is nothing wrong with your code, except that now SharePoint 2010 is 64bit!
You got it right, your SharePoint Server 2007 console application’s target platform would have been x86(32 bit) and you need to change that to x64(64 bit) in the Build configuration of your project.
The other thing to make sure is that the target framework is .NET 3.5.