Common issue: new SPSite API call returns "The Web application at http://server:port/ could not be found."

Since the early times of SharePoint we receive support cases where a customer receives the following error message when using custom code with SharePoint:

"The Web application at http://server:port/ 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"

Here are the most common reasons this error can occur:

  1. The code is executed on a different machine – The SharePoint object model (except the Client API) requires to be run on the SharePoint server itself. It is not possible to run the application on a server which is not within the same SharePoint farm the code is trying to access.
  2. Insufficient Rights on the site collection – The code is executed in context of an account which does not have read permission on the site collection
  3. Incorrect Url being used – Verify that the site works correct in a browser and double check that the server is correct registered in the AAM settings
  4. Incorrect bitness – The SharePoint object model needs to be executed with the same bitness as the operating system. That means you cannot use the SharePoint object model in a 32-bit application if the Operating System and SharePoint are installed as 64-bit version. Ensure to compile the project using the correct bitness (64-bit on a 64-bit machine vs. 32-bit on a 32-bit machine)
  5. Incorrect .NET framework version –  Ensure that the project is configured to use .NET 3.5 for SharePoint 2010 and below and .NET 4.0 for SharePoint 2013

Comments (30)

  1. Straight to the point!!

    nice one!!!

  2. anonymouscommenter says:

    I hit the point 5!

  3. anonymouscommenter says:

    Great post Stefan,
    I had the bitness wrong. Visual Studio 2010 set my console application to x86. I changed it to "Any CPU".

  4. anonymouscommenter says:

    Very useful, Ur blogs always provide the exaustive options 🙂

  5. Sagir Kazi says:

    #3 did the trick for me. One web application with multiple URLs. Adding to AAM solved the issue. Very helpful post!

  6. anonymouscommenter says:

    Excellent post

  7. anonymouscommenter says:

    Very helpful. had a bunch to check.

  8. anonymouscommenter says:

    I also have one web application with different URLs. What does it mean by " double check that the server is correct registered in the AAM settings". I don't have access to central admin of the server as this is production environment and I am trying to
    deploy Sequential WF. Is there sth I am not doing correctly in my workflow as I am using workflowProperties.Web to get the web site whenever required.

  9. Hi Nix,
    each Url used to access the relevant sharepoint web applicaiton either through the browser or the API has to be listed in an AAM zone.

  10. anonymouscommenter says:

    Very much helpful. Thanks

  11. anonymouscommenter says:

    I hit the point 5. it was a great help

  12. anonymouscommenter says:

    Thank you for the posts! Mine was a variation of #2 – my account did not have logon rights to the SQL Server database Sharepoint was using. I found this in the Event Viewer – hopefully it'll help others:

    SQL database login for 'SharePoint_Config' on instance '[xxxx]' failed. Additional error information from SQL Server is included below.

    Login failed for user '[yyyy]'

  13. anonymouscommenter says:

    Thanks Dana! Same problem for me 😉

  14. anonymouscommenter says:

    I am new to sharepoint and we have s sharepoint server and the .net application using SPSite object is in my local machine.
    I was trying to connect to the sharepoint site from my local machine using SPSite object and I got the "The Web application at http://server:port/ could not be found." error. Please let me know what are the things that I should check for the application to
    run. Thank you

  15. Hi Jeff,
    please check the 5 points above.

  16. anonymouscommenter says:

    I experience for number 1. very helpful, thanks a lot.

  17. anonymouscommenter says:

    Hours of searching solved by this post…


  18. anonymouscommenter says:

    3rd point worked for me…Thanks 🙂

  19. anonymouscommenter says:

    Thanks! Bitness was the Problem for me

  20. anonymouscommenter says:

    Ditto for me on Dana's issue, thank you for posting! 🙂

  21. anonymouscommenter says:

    Stefan, thank you very much! Your article avoids me hours of painful googling. I tried to execute server code (Microsoft.SharePoint.dll) on client machine without Sharepoint and couldn't understand why nothing worked.

  22. Steve Xue says:

    Thanks Dana, points 4 and 5 fixed our issue. 🙂

  23. ravneet singh says:

    I am new to Sharepoint and my question is if i am using the Central Admin URL to get SPSite my code works ,otherwise it shoots the above Exception

    1. The Url needs to be the Url of the specific site collection you would like to connect to.


  24. Quite useful post, Jeff!
    Hit at point 3. Worked.

  25. john zachariah says:

    Thank you ! for me Incorrect bitness worked ! It saved my time 🙂

  26. Gleb says:

    Please add 6. point – Need rights to Sharepoint Config Database.

  27. Perla Nava says:

    Nice Post and to helpful! for me was the option 1. what can I do if I need to create SiteCollections from Farm1 to Farm2? Is it possible do it by Event Handler? please help I’m a bit lost

    1. Hi Perla,
      I’m not sure what you are trying to achieve. Can you elaborate?