none
SPSite - The Web application at <address> could not be found.

    Question

  • I'm trying to use SP object model from a web application and when I create a new instance of SPSite I get this error:

    The Web application at <address> 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.

    I've tried loading the SPSite using the server name, server IP address or localhost, but in each case I get this error.
    The web application is run from the SP server.
    What's wrong/missing?
    Monday, December 07, 2009 5:20 PM

Answers

  • You cannot use the VS2010 testing framework (MSTest) with SharePoint. VS2010 and its test framework run in 32-bit mode, which will not work with SharePoint 2010 as it is in 64-bit mode.
    • Proposed as answer by Mike Hacker Wednesday, January 13, 2010 9:40 PM
    • Marked as answer by tsw_mik Thursday, January 14, 2010 9:40 AM
    Wednesday, January 06, 2010 10:20 PM

All replies

  • You need to change the target platform to x64 as SharePoint is now 64bit.

    Refer here for more information.

    Hope that helps.
    Regards,
    Chakkaradeep || SharePoint Developer - MCTS SharePoint Dev, WSS Dev
    http://www.intergen.co.nz || Twitter: http://twitter.com/chakkaradeep || http://www.chakkaradeep.com
    Monday, December 07, 2009 7:23 PM
  • Hi,

    This is most likely because you're targeting x86 in your application instead of x64, just like Chakkaradeep says.

    You should try to target AnyCpu, and of course make sure you're targeting Microsoft .NET Framework 3.5.

    Normally I like to compile my generic SharePoint code in AnyCpu mode, because when it's going to work in WSS 3.0/MOSS 2007 running 32-bit as well if that would ever be necessary. If you target it to x64 it will only work with 64-bit environments.

    Regards,
    Tobias Zimmergren
    Microsoft MCP, MCTS, MCT, MVP (SharePoint)
    Blog: www.zimmergren.net
    Twitter: twitter.com/zimmergren
    Monday, December 07, 2009 9:51 PM
  • The default target is AnyCpu and that's when I'm getting that error.
    When I change to x64 I get this:
    Could not load file or assembly 'WebApplication_Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
    I'm using VS2010 Beta 2 and I tried targeting .NET 3.5 as well as 4.0.

    Tuesday, December 08, 2009 9:35 AM
  • >>WebApplication_Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

    Is this your custom assembly? If so, what is its target framework?

    Regards,
    Chakkaradeep || SharePoint Developer - MCTS SharePoint Dev, WSS Dev
    http://www.intergen.co.nz || Twitter: http://twitter.com/chakkaradeep || http://www.chakkaradeep.com
    Tuesday, December 08, 2009 10:00 AM
  • Hi,

    Did you sign your project with a strong key?
    Your custom assembly (WebApplication_Test) looks like it doesn't have a PublicKeyToken.

    You'll need to have a PublicKeyToken (e.g. sign your project with a .snk or .pfk) in order to get that.
    Tobias Zimmergren
    Microsoft MCP, MCTS, MCT, MVP (SharePoint)
    Blog: www.zimmergren.net
    Twitter: twitter.com/zimmergren
    Tuesday, December 08, 2009 10:02 AM
  • WebApplication_Test is a web application project.
    There are no other projects in the solution and no external assemblies are used (except 14/ISAPI/Microsoft.SharePoint.dll)
    It's what you get when you create a new web application from VS2010 and nothing more.
    That error I'm getting when targetting 3.5.
    When targetting 4.0 the error is slightly different: Could not load file or assembly 'WebApplication_Test' or one of its dependencies. An attempt was made to load a program with an incorrect format.
    I want to use this project just for testing, do I really need to give it a strong name?
    I don't remember doing this for SP2007.


    Edit: I made a test and signed the assembly and now I'm getting the same error, but with the PublicKeyToken not being null.
    Tuesday, December 08, 2009 10:15 AM
  • I tried the same code in a windows forms app and it works fine.
    It's just the web app that's not working.
    Any ideas?
    Tuesday, December 15, 2009 12:35 PM
  • You cannot use the VS2010 testing framework (MSTest) with SharePoint. VS2010 and its test framework run in 32-bit mode, which will not work with SharePoint 2010 as it is in 64-bit mode.
    • Proposed as answer by Mike Hacker Wednesday, January 13, 2010 9:40 PM
    • Marked as answer by tsw_mik Thursday, January 14, 2010 9:40 AM
    Wednesday, January 06, 2010 10:20 PM
  • I too was facing the same issue while trying to get SPSite object from a Site URL in SharePoint 2010.

    The line of code tht was failing was

    SPSite site = new SPSite(strUrl);

    The error was "The web application could not be found at the given URL.... ".




    Building the Code with 'Any CPU' as the target did the trick for me..

    Thanks.... :)...
    Thursday, March 11, 2010 9:49 PM
  • I was Facing Same issuue with SPSite object in my Application.

    I followed below Steps for solution :

    1.  I closed visual studio 2010, and opened it again by right clicking on it and selecting “Run as Administrator”

    http://www.sharepointsteve.com/2010/05/visual-studio-2010-cant-open-an-spsite-object-in-server-2008-r2/

     

    2. Then changed Target Framework to X64 from Project Properties Since

    "VS2010 and its test framework run in 32-bit mode, which will not work with SharePoint 2010 as it is in 64-bit mode."

    Now My Code Works SuccessFully !!

    Cheers

    Happy SharePointing  

     

     


    Manesh
    Thursday, June 03, 2010 1:46 PM
  • You can't use Sharepoint.dll which is 64 bit with Development Web Server in Visual Studio which is 32 bit. Even if you set target platform to 64bit, Server can't load your web application dll which you experienced too.

    Only solution is to move your web app to IIS on 64 bit OS and not to forget to set your web application pool identity to same account your sharepoint app pool runs (that would be network service in most cases).

    Tuesday, August 24, 2010 8:56 AM
  • This issue is related Access permission Give the permissions like below or read more in my blog

    http://sharepointinstallation.blogspot.com/2010/12/minimal-permission-required-to-execute.html

    User Permission

    SharePoint Site Minimum Read Permission
    Sharepoint Server Add to WSS_ADMIN_WPG group
    Database Sharepoint Content DB (Site collection database) - db_owner permission
    Sharepoint Config DB (Config DB of sharepoint installation) - - db_owner permission

    Friday, December 03, 2010 10:21 PM
  • Hi,

        I also have the same problem.

        The default target is AnyCpu and that's when I'm getting that error.

         

    SPSite site = new SPSite("http://sh-sharepoint:9002/");//
    

     this line throws 

    The Web application at http://sh-sharepoint:9002/ 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.

     

    When I change to x64 I get this:

    Server Error in '/' Application.

    Could not load file or assembly 'SearchResult, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5f8e8b52e370a6ab' or one of its dependencies. An attempt was made to load a program with an incorrect format.

     

    I'm using VS2010 version 10.0.30319 RTMRel and I tried targeting .NET 3.5 as well as 4.0.

     

    I find your problem have been resolved,Could you tell me how you get it ?

     

    thank you 


    In God We Trust
    Thursday, January 12, 2012 5:58 AM
  • Fiyoung, if you took the time to read the answer to the question you posted in, you'd see that the answer was simply that it can't be done.
    Thursday, January 12, 2012 10:07 PM
  • hi,

        Thank you for your advise

        When i restart the fast search server and sharepoint server,it works ok.

     

       Best regards.


    In God We Trust
    Wednesday, January 18, 2012 2:20 AM