The below exception is very frustrating when we start working with SharePoint object model. Let us investigate how to solve below exception

clip_image001

Above Exception can encounter in two scenarios

1. Trying to use SharePoint 2010 object model in managed application like console or windows application.

2. Trying to use SharePoint 2010 object model in WCF Service or Web services.

Scenario # 1: The above Exception in console or windows application

Right click on Console/Windows Application project and select properties.

clip_image002

Click on Application tab and choose the target framework to .Net Framework 3.5

clip_image004

After changing Target framework to .NET Framework 3.5, click on Build tab

clip_image006

Change the Platform target to Any CPU.

Now when you run the application, you should not get the above exception

Scenario # 2: Above Exception when using SharePoint 2010 object model in WCF

If you are getting above exception while using SharePoint object model in WCF or any Web service. You need to perform below operations

Host WCF service in IIS. See the below link for step by step explanation on how to host WCF 4.0 Service in IIS 7.5

http://dhananjaykumar.net/2010/09/07/walkthrough-on-creating-wcf-4-0-service-and-hosting-in-iis-7-5/

Only we need to make sure that,

Hosted WCF service is sharing the same application pool with SharePoint.

clip_image007

Select the Application pool to SharePoint-80

Try to apply both when you use SharePoint 2010object model. I hope this discussion will help you.

Advertisements

57 thoughts on “The Web Application could not be found .verify that you have typed the URL correctly error: SharePoint 2010 object model

  1. This is great to know and I’m glad you published it to save me from a really bad day. 🙂

    Do you happen to know why we have to host within the same application pool as Sharepoint? It seems really strange that a console app, etc. running in x64 bit mode can connect fine but the WCF application fails unless it is bound by the same app pool.

  2. Hi,
    It works for object model .I i tried to create new SPSite through webapplication that is aspx code behind file i am still getting the error.
    Please do a favor.

    siddarth

  3. Hi,

    Thanks for the solution.

    We are accessing sharepoint 2007 (64 bit) data using Object model using a console application (64 bit). The application run fine if we run through local command prompt (on which Sharepoint server machine exist). When we try to run the same application from remote machine (32 bit) using WMI it launches but fails to get the results. We are providing administrator permissions to the process.

    Can you please give some hint why this is happening? Thanks in advance.

    Thanks,
    Krishnakant

  4. Hi,
    I am using scenario#2 above. However I am unable to determine two locations where apppool should be same. One location is where SharePoint site is host in IIS. SO i know that appPool. Now my web service is actually hosted on same server in same SharePoint web app. So how do I verify web service’s app pool.
    Additional Info:
    My service works fine and I am able to create sitecollection successfully. However when I am trying to use webservice from another machine(XP) then I am agetting url not found error.
    Please comment.

  5. Hello Sandip

    you are not able to access service on other machine and that is altogether different problem.

    That might be due to some other issues like firewall is blocking the service .

    This post was to work on object model on a service. Now your service is succefull accessing object model and running. You wanted to access on other XP machine just check for firewall settings.

  6. Thanks for quick response Dhananjay.
    I do not supect firewall problem as other methods from same service are running fine. E.g. I have CreateSubSite method which is running fine from both server and from my local machine too.
    In my CreateSiteCollection method I am using SelfServiceCreateSite() API. Now this method works on server however not work on my local machine. I am getting an “The Web application at http://server url/XX/XX could not be found. Verify that you have typed the URL correctly.” error. That’s why I post my comments here.
    So can you please throw some light on what could be the problem. I feel it’s permission issue but then what permission and what is resolution?
    Thanks,
    Sandip

  7. Hi Sandip ,

    What I understood is ,

    1. You created a Service

    2. Inside Service you have a method called CreateSiteCollection() . Insdie method you are using SelfServiceCreateSite()

    3. In same service you have CreateSubsite() ? and this is running fine

    4. On client side from the same service , method CreateSubsite() is running whereas method CreateSiteCollection() is not running ?

    IF this is the case I supsect API SelfServiceCreateSite() is the culprit. Since that is creating a site collection , it might need some extra parameter from client and you are not provindg that

  8. Hi Dhananjay,
    You have understood it perfectly. I am using SelfServiceCreateSite(). I have implemented solution from following link.
    http://peterheibrink.wordpress.com/2009/09/09/self-service-site-creation-through-code/
    Well, I will look into it’s parameters or more information around it.
    However just want to give some history of my problem and why am I using SelfServiceCreateSite().

    1. I was using SPSite and SPWeb objects to create sitecollcetion (web.collections.Add()). It was always failing, even on server none of my code was working for it. I tried all possible solutions like using elevated previlages etc. However all were failing to create Sitecollection giving either “Access denied” or some other error.
    2. So while searching on that problem i found SelfServiceCreateSite() usage. And it works on server so I thought let’s use it.
    3. Well, and surprisingly my CreateSubSite method is still using following standard code which works just fine.
    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
    using (SPSite siteCollection = new SPSite(parentSiteUrl))
    {
    using (SPWeb parentWeb = siteCollection.OpenWeb())
    {
    if (parentWeb.Webs[siteUrl].Exists)
    {
    parentWeb.Webs.Delete(siteUrl);
    }
    SPWeb newSubSite = parentWeb.Webs.Add(siteUrl, siteTitle, description, LCId, siteTemplate, false, false);
    newSubSite.Update();
    newSubSite.AllowUnsafeUpdates = false;
    newSiteUrl = newSubSite.Url;
    newSubSite.Dispose();
    }
    }
    });

    4. we are using custom membership provider on SharePoint server which is configured properly.

    Now if you already know better way of creating site collection then please let me know.

    Also let me know if I need to post it into differnet thread.

    Thanks again,
    Sandip

  9. One quick question , did you try to create site collecetion manaually ? are you working on Windows7 or Server2008 ?

  10. 1. I am using WSS 3.0. Sharepoint is installed on Win2003 server having .net 3.5 installed on it.
    I have develope web service in .net 3.5 (platform set as Any CPU) on my local machine which is WinXP machine.
    After any change in service i re-deploy service on Win2003 server again.

    2. Yes I am able to create SiteCollection manually on SharePoint server. I have one local user(AA) created there who is also farm admin.
    However in custom membership provider we have only one user(BB) hardcoded and that is different than local user AA.
    So web applications already created on SPServer has BB as primary admin for all SiteCollection.
    Please let me know if you required more information.

    Thanks,
    Sandip

  11. I am newbie to SharePoint so don’t know how to check SP version. When i checked ‘Servers in Farms’ in Central Admin I found server’s Version is 12.0.0.6421.
    And in ‘Add or Remove Programs’, I found only Window SP Services 3.0 (version:12.0.6425.1000). I am not sure whether we have SP2007.

  12. Hi Dhananjay,
    I have checked with SelfServiceCreateSite() method nothing is wrong into it.
    However I feel “Access Denied” is main cause of all our errors. As creating sitecollection required extra permissions and context should be same. This doesn’t match when we call it from other machines.
    So can you please give any inputs over this scenario: Which method(way) should we use to create sitecollection from remote machine. How should we authenticate and then authorise user so that it will have all nencessary permissions to create sitecollection.
    Thanks,
    Sandip

  13. When i try connect with sharepoint object model, i am getting this error in web application.I am using VS2010 and SharePoint 2010.
    SPSite sharePointSite = new SPSite(sharePointRoot);
    The Web application at http://Server:8080/Lists/ListName 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.

  14. Hi Sahil ,

    are you providing List/Listname also in URL while creating instance of WebApplication. Try to give only base URL and see if you are getting exception

  15. Hi Sahil,
    Go to your sharepoint server and check whether this url is accessible. Also give only base url while creating SPSite object.

    Sandip

  16. Hi,
    I was working on my share point application and accidently I have deleted root level site. Can you please tell me how to re-create it.
    E.g. My original web app url was: http:///sites/
    And I used to access it directly from browser.
    And now I am not able to access it as from this site itself I choose option to delete site(thinking this will only delete sitecollection). So ‘/sites/’ got deleted. Is there any way to recreate it.
    I can still my web application in central-admin as http:///.

    Thanks,
    Sandip

  17. In above query Server name was got hide due to html. Consider “http:///sites/” means “http://ServerName/sites/”

  18. The Web application at http://james:8888/ could not be found. Verify that you have typed the URL …
    Jun 13, 2011 09:31 AM

    Hi All,

    1.Hi I have created an asp.net application which is running on X64 bit or Any CPU.Even i am running VS2010 as administrator.

    2.I have targeted my asp.net application on .NET FRAMEWORK 3.5

    3.I have targeted platform Any CPU or X64

    4.I have created a Sharepoint 2010 site ie http://james:9090 and application pool for this site is [Sharepoint Portal 9090]

    Note:-“James” is my system server name

    5.Now i am trying to opne this site SPSite sharePointSite = new SPSite(“http://james:9090”);

    6.When i copy this url and paste in browser then this site is running fine(means existing)

    7.Open Server Manager -> expand role->Clicking IIS Manager(My site and application pools are existing under [JAMES\Administrator].

    8.I have set Managed pipeline mode of my site application pool [Sharepoint Portal 9090] to “Integrated” Identity to “Local system” or “James\Administrator”

    9.Now i am trying to opne this site SPSite sharePointSite = new SPSite(“http://james:9090”); and getting error

    “Web application 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 null'”

    Can you please tell me exact steps where i need to change and what i need to change so that i can be able to open Sharepoint 2010 site?

    As i remembered same thing i was using on Sharepoint 2007, It was working fine but i know why its not working on Sharepoint 2010.

    Note:- I asked this question on Sharepoint forum but They are telling ask on ASP.NET forum.So asking here..

    Thanks,

  19. The Web application at http://james:8888/ could not be found. Verify that you have typed the URL …
    Jun 13, 2011 09:31 AM

    Hi All,

    1.Hi I have created an asp.net application which is running on X64 bit or Any CPU.Even i am running VS2010 as administrator.

    2.I have targeted my asp.net application on .NET FRAMEWORK 3.5

    3.I have targeted platform Any CPU or X64

    4.I have created a Sharepoint 2010 site ie http://james:9090 and application pool for this site is [Sharepoint Portal 9090]

    Note:-“James” is my system server name

    5.Now i am trying to opne this site SPSite sharePointSite = new SPSite(“http://james:9090”);

    6.When i copy this url and paste in browser then this site is running fine(means existing)

    7.Open Server Manager -> expand role->Clicking IIS Manager(My site and application pools are existing under [JAMES\Administrator].

    8.I have set Managed pipeline mode of my site application pool [Sharepoint Portal 9090] to “Integrated” Identity to “Local system” or “James\Administrator”

    9.Now i am trying to opne this site SPSite sharePointSite = new SPSite(“http://james:9090”); and getting error

    “Web application 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 null'”

    Can you please tell me exact steps where i need to change and what i need to change so that i can be able to open Sharepoint 2010 site?

    As i remembered same thing i was using on Sharepoint 2007, It was working fine but i know why its not working on Sharepoint 2010.

    Note:- I asked this question on Sharepoint forum but They are telling ask on ASP.NET forum.So asking here..

    Thanks,

  20. How can you host a WCF 4.0 service in a non .Net 4.0 application pool? As soon as I change the configuration I get:

    “Unrecognized attribute ‘targetFramework’. Note that attribute names are case-sensitive.” error in web.config.

  21. Hello pals,

    I’m facing exactly the same problem as Sandip had before. I’ve a custom WCF service deployed on IIS 7 (using SP 2010).
    This WCF service has 2 methods – one simple method returning “hello world” and another using SP object model – SPSite, SPWeb, SPList, etc.

    Initially I had problem in consuming this 2nd method even locally using a console app client, as it was throwing FileNotFoundException while trying to instantiate SPSite object by providing a valid URL. Later this issue got resolved by providing complete admin access to the site collection.

    Now, I’m trying to consume the same WCF service from a Java client remotely and have provided the NTLM credentials. Am able to invoke SharePoint’s built-in services like Lists, Search, Web, etc and even the first method in the WCF service.
    But when I call the 2nd method which uses SP object model, am facing the same FileNotFoundException issue again…

    I’m sure this is again something related to permissions. But not finding a way to fix this.
    Hope, Sandip has got the solution for this problem.
    Kindly throw some light.

    Thanks in advance,
    Praveen

  22. I’ve also tried running with elevated privileges option. People recommend to use the same application pool as SP 2010. i.e SharePoint-80. As the WCF service would be deployed in the same web application where SharePoint exists, even the service must be using the same application pool as SP. Am not sure why it is still throwing permission issues…

    Also I’ve checked the .NET version, platform as explained in this post.
    Kindly help.

  23. I had this problem before setting x64 instead of x86. then i set x64 as target platform. When i am log in with spadmin credentials its works fine but its not work while i am log in with ordinary user account. please give me the solution

  24. For the WCF solution, i also have such a service with a 4.0 Runtime, but SharePoint has only a 2.0 Runtime, it will not work for me :/

  25. for Senario 2#, your WCF must be on created using .NET 3.5. When deploy to IIS 7 (Windows 2008) make sure of the following:

    1) application pool – .net framework v2.0… (i know but i will work for .NET3.5 wcf)
    2) application pool – enable 32bit = false
    3) application pool – identity = networkservice
    4) website iis authentication = make sure windows authentication is enabled

    I got it working by doing the above..i’m using Sharepoint2010 on Win2008R2.

  26. Greate post. Keep posting such kind of info on your page.
    Im really impressed by it.
    Hi there, You’ve done an incredible job. I’ll certainly digg it and personally suggest to my friends.
    I am sure they will be benefited from this
    site.

  27. We’re a bunch of volunteers and opening a brand new scheme in our community. Your site provided us with helpful information to paintings on. You might have done an impressive job and our entire group may be grateful to you.

  28. After I originally left a comment I appear to have clicked on the
    -Notify me when new comments are added- checkbox and from now on each
    time a comment is added I receive four emails with the same comment.

    Is there a way you are able to remove me from that service?

    Kudos!

  29. With havin so much written content do you ever run into any issues of plagorism or
    copyright violation? My website has a lot of exclusive content I’ve either written myself or outsourced but it appears a lot of it is popping it up all over the web without my authorization. Do you know any solutions to help protect against content from being ripped off? I’d certainly appreciate
    it.

  30. Excellent tip about the WCF Application pool using the same pool as SharePoint 2010. That fixed the problem for me. Nice one.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s