[Solved] SharePoint System.IO.FileNotFoundException was unhandled

Posted on : Fri, 18th Sep 15 09:42 am (Updated on : Fri, 18th Sep 15 09:42 am) UTC
Author : Code2care
100+ votes

Visual Studio Console Application - SharePoint

Creating a Visual Studio console application for SharePoint is a good idea if you want to do a small POC (proof of concept). This saves good amount of time and the overhead of deployment and server reset.
We will not focus on creating console application, but learn how to resolve/fix the most common error which developers face here - "FileNotFoundException was unhandled"

Error - System.IO.FileNotFoundException was unhandled

This error occurs because Visual Studio console applications run on the 32 bit mode by default, but SharePoint (2010 and above) is built on the 64 bit mode.

The error says - System.IO.FileNotFoundException was unhandled.
The error description says - The Web application at http://yoursharepointsite could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

SharePoint Console application error - FileNotFoundException was unhandled

How to fix ?

In order to fix the issue simply change the Build platform target to 64 bit (x64).

Steps - From the Solution Explorer, right click on the project and click "Properties", click on "Build" and change the Platform target to x64 (64 bit). Save the changes.

SharePoint console application - Change project build from 32-bit to 64-bit

Re-run your application and this time it will run as expected with any issues.

Code2care's mission is to share varied knowledge in technical and non-technical areas gathered during day-to-day learnings and development activities so that our visitors can leverage this portal to find solutions to their queries without re-inventing the wheel. Technical posts include Learnings, Tutorials, Video Tutorials, Code Snippets, Tips-n-tricks.

Follow us : Facebook - Twitter - Google +