in

Dot Net Mafia

Group site for developer blogs dealing with (usually) .NET, SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, and other Microsoft products, as well as some discussion of general programming related concepts.

This Blog

Syndication

Archives

Corey Roth [MVP]

A SharePoint MVP bringing you the latest time saving tips for SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, MOSS 2007, ASP.NET, LINQ, and Visual Studio 2012.

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

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

 

Mike said:

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

April 16, 2010 5:05 PM
 

George said:

What about ASP.NET applications?

Where we can find Platform Target to change it?

Regards

May 26, 2010 6:57 AM
 

nikhil said:

Thanks, it resolve my issue :)

July 13, 2010 4:45 AM
 

JS said:

Many thanks, this solved my issue.

August 16, 2010 9:21 AM
 

Tamar Mansherov said:

Great job! thanks a lot!!!

September 15, 2010 10:51 AM
 

System.IO.FileNotFoundException on "SPSite = new SPSite(url/IP)" « Ammar's IT Blog said:

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

December 23, 2010 1:14 PM
 

Shan said:

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??

December 28, 2010 7:01 PM
 

Mohit Ahuja said:

Hey Thanks a ton!

Its resolved my issue.

July 15, 2011 3:14 AM
 

Nirav Mehta said:

It worked...thanks

October 5, 2011 12:53 AM
 

Niraj Patel said:

Thanks Corey.   It worked.

December 23, 2011 6:31 PM

Leave a Comment

(required)  
(optional)
(required)  
Add

About CoreyRoth

Corey Roth is an Applications Architect at Infusion specializing in ECM and Search.
2012 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems