Debugging SharePoint – Web application could not be found Issue

Sometimes when I debug my SharePoint code from Visual Studio, I get the exception:

System.IO.FileNotFoundException was unhandled
  Message=The Web application at
http://jl-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.
       at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken)
       at Microsoft.SharePoint.SPSite..ctor(String requestUrl)
       at SPConsoleApplication_SPRouterRule.Program.Main(String[] args) in C:\Install\SPConsoleApplication_SPInstall.Solution\SPConsoleApplication_SPRouterRule\Program.cs:line 33
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

Most often this is due to one of three things:

  • Must run as administrator
  • Wrong target framework
  • Wrong target application


Run as administrator

The Visual Studio instance must be started as “Run as administrator”.


Target framework: .NET Framework 3.5

Visual studio creates a new console application with the setting  .NET 4.0 . For SharePoint you need to set it to .NET Framework 3.5


Platform target: Any CPU

Visual studio creates a new console application with the setting  x.86 . For SharePoint you need to set it to Any CPU


Comments (5)

  1. Steve says:

    Great Post – Short, Sweet and to the point.


  2. Rick Stokes says:

    Yes, ANY CPU resolved the issue. Thanks so much

  3. Nowshad says:

    I have tried all these steps but it  gives the same error, can you tell me what else i can do to make this run?

  4. Jagdish says:

    Thank you so much for this post. I was finally able to get my first sharepoint program to work.

  5. BK says:

    Hi ,

    Great post, Is ther enay way to turn debugging on for a extended site ? i have extended the site to a URL ( for internet facing. and i cant get to debug issuees on my code in real time.