The Latest Time Saving Tips for Your SharePoint Deployment

Corey Roth

Subscribe to Corey Roth: eMailAlertsEmail Alerts
Get Corey Roth: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Related Topics: SharePoint Archiving Journal, Microsoft Developer, CIO/CTO Update

Blog Feed Post

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.

Read the original blog entry...

More Stories By Corey Roth

Corey Roth, a SharePoint Server MVP, is an independent consultant specializing in Cloud technologies such as Azure and Office 365. He also specializes in mobile development. Corey serves as the product manager for two cloud-first mobile app platforms: BrewZap and HappenZap.