Share-n-dipity

SharePoint serendipity is the effect by which one accidentally discovers something fortunate, especially while looking for something else entirely. In this case, it is the occassional musings, observations, and Ouija board readings about the phabulously

File Not Found Error with SharePoint 2010 and Visual Studio 2010

File Not Found Error with SharePoint 2010 and Visual Studio 2010

  • Comments 1
  • Likes
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.
Comments
  • I got the same problem

    Any CPU, v3.5

    Still same problem......Any Help

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment