File Not Found Error with SharePoint 2010 and Visual Studio 2010
Hey folks, I've had this happen to me a couple of times and it's driven me a little crazy figuring out what was going on. You may use Visual Studio 2010 to create a new SharePoint 2010 application. You do something innocuous like using (SPSite theSite = new SPSite(myUrl)) and when the code executes, you get the dreaded "file not found" exception. So what's going on? Well what I've seen happen to myself and a few others, is that VS 2010 is targeting the .NET Framework 4.0 by default. SharePoint 2010 is using the .NET Framework 3.5. So the first step is you go in and change the version of the framework you are targeting to 3.5. You go and run your app again and what happens? Same error. Well the problem it appears is that when you change the target framework version, it also changes the target CPU from Any CPU to x86. Of course, SharePoint 2010 is only x64, so of course when your x86 app tries to load an x64 assembly, it fails and and in really weird way the file not found exception then makes sense. Okay, that's kind of apologistic but you get the gist. So step 2 here is obviously to go back and change your target CPU back to Any CPU and you should be good. That has fixed the problem a number of times for different people now - hope it helps you too.