Error: System.IO.FileNotFoundException: The web application at <servername> could not be found (Console Applications with SP2010)

Posted Tuesday, December 1, 2009 10:33 AM by CoreyRoth

If you have tried to build a quick console application using Visual Studio 2010 to work with SharePoint 2010, you might find that you run into the following error.

Unhandled Exception: System.IO.FileNotFoundException: The Web application at http://sp2010 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. 

Consider the following console application.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Microsoft.SharePoint;

 

namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            using (SPSite siteCollection = new SPSite("http://sp2010"))

            {

                Console.WriteLine("Site Title: {0}", siteCollection.RootWeb.Title);

            }

 

            Console.ReadLine();

        }

    }

}

All this console application does is display the title of the root web of the site collection.  However, when I run it, I get the FileNotFound error. 

ConsoleApplicationFileNotFoundException

You first might think to check your path or something like that, but this is actually caused by a completely different issue.  As you know by now, SharePoint 2010 is a 64 bit application.  However, when you create a new Console Application, it does not default to x64, it defaults to x86 as shown below.

ConsoleApplicationBuild

View your project properties, go to the Build tab and change the platform target to x64.  Run your console application again and everything should work as expected now.

ConsoleApplicationWorking

This doesn’t just apply to Console applications, but could also apply to any other type of external application you might build.  Just make sure it is set to x64.  Technically Any CPU would work as well, but SharePoint only runs on x64 so you might as well just use that.

Comments

# re: Error: System.IO.FileNotFoundException: The web application at <servername> could not be found (Console Applications with SP2010)

Friday, April 16, 2010 5:05 PM by Mike

My application continues to have this exception even when I change it to x64.  Any other things I should look at?

# re: Error: System.IO.FileNotFoundException: The web application at <servername> could not be found (Console Applications with SP2010)

Wednesday, May 26, 2010 6:57 AM by George

What about ASP.NET applications?

Where we can find Platform Target to change it?

Regards

# re: Error: System.IO.FileNotFoundException: The web application at <servername> could not be found (Console Applications with SP2010)

Tuesday, July 13, 2010 4:45 AM by nikhil

Thanks, it resolve my issue :)

# re: Error: System.IO.FileNotFoundException: The web application at <servername> could not be found (Console Applications with SP2010)

Monday, August 16, 2010 9:21 AM by JS

Many thanks, this solved my issue.

# re: Error: System.IO.FileNotFoundException: The web application at <servername> could not be found (Console Applications with SP2010)

Wednesday, September 15, 2010 10:51 AM by Tamar Mansherov

Great job! thanks a lot!!!

# System.IO.FileNotFoundException on &quot;SPSite = new SPSite(url/IP)&quot; &laquo; Ammar&#039;s IT Blog

Pingback from  System.IO.FileNotFoundException on &quot;SPSite = new SPSite(url/IP)&quot; &laquo; Ammar&#039;s IT Blog

# re: Error: System.IO.FileNotFoundException: The web application at <servername> could not be found (Console Applications with SP2010)

Tuesday, December 28, 2010 7:01 PM by Shan

I use  VS 2008. I created a C# Console application and target framework is 3.5. I try to open the web of a MOSS 2007 server url and get the same error. Any idea what should be changed??

# re: Error: System.IO.FileNotFoundException: The web application at <servername> could not be found (Console Applications with SP2010)

Friday, July 15, 2011 3:14 AM by Mohit Ahuja

Hey Thanks a ton!

Its resolved my issue.

# re: Error: System.IO.FileNotFoundException: The web application at <servername> could not be found (Console Applications with SP2010)

Wednesday, October 5, 2011 12:53 AM by Nirav Mehta

It worked...thanks

# re: Error: System.IO.FileNotFoundException: The web application at <servername> could not be found (Console Applications with SP2010)

Friday, December 23, 2011 6:31 PM by Niraj Patel

Thanks Corey.   It worked.

# re: Error: System.IO.FileNotFoundException: The web application at <servername> could not be found (Console Applications with SP2010)

Thursday, December 25, 2014 4:09 AM by mimi

Thank u so much! wuuuuuiiiii that was exhausting

# re: Error: System.IO.FileNotFoundException: The web application at <servername> could not be found (Console Applications with SP2010)

Thursday, June 4, 2015 9:45 AM by Atif Ghayas Siddiqui

Thank you so much! It worked for me

We can also select 'Any CPU'

Leave a Comment

(required)
(required)
(optional)
(required)