SharePoint – System.IO.FileNotFound Error in Console Application
I was working on a console app that would use the SharePoint API to manage/validate some site settings. After writing out the “skeleton” of the application I tried to debug it with Visual Studio to make sure everything was working so far.When the application hit the first call that referenced the SharePoint API it would throw a System.IO.FileNotFound exception.
I searched around as I couldn’t understand what could be causing this. My executing account had full Rights in SharePoint, the local system and access to the database. I checked to ensure the url I was using was correct and that everything worked when viewing the site using a browser. Then I realized that Visual Studio by default sets Console applications to target x86 by default!!
This is a problem as the SharePoint API is 64bit only and my console application was running in 32bit mode. I checked Task Manager to view the running processes and sure enough my app was running with *32 indicating it was running in 32bit mode.This was a quick fix as I just needed to update the Platform Target build setting to be x64 instead of x86.
To do this navigate to Project Properties > Build tab and update the Platform Target to be x64 instead of x86. Once this is done run the application again to validate that the issue is resolved. Also make sure you update all of your build configurations. When you switch from Debug to Release the release configuration will still be set to target x86.
Note: Setting to AnyCPU will also work as it will run in 64bit, but since the SharePoint API is 64bit only, I suggest setting to x64 to ensure it does not run on 32bit systems.
