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"
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.
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.
Code2care'smission 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.