Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm trying to use SP 2010 site from a web application and when I create a new instance of SPSite I get this error: The Web application at 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 know that this question is common over the net but I didnt find the solution for me The Code:

  SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            using (SPSite site = new SPSite("http://servername:port"))
            {
                elevatedWeb = site.OpenWeb();
            }

1.I run my code on sharepoint server its the same machine

2.I copy paste the Url to browser and its work

3.I use .NET 3.5 Framework

4.I have full permission on site for administrator account and also dbowner

5.I used platform target Any CPU my sharepoint is 64 and when Im try to make it 64 i face a problrm with my Dll: "Could not load file or assembly or one of its dependencies. An attempt was made to load a program with an incorrect format."

Any Suggestion for that big problem

share|improve this question
1  
What URL are you using to connect to your site collection and what is the URL to your site collection? –  Robban1980 Aug 6 '12 at 8:28
    
What are you developing? Console application? Event receiver? Web part? –  Anders Rask Aug 6 '12 at 8:51
    
I said web application –  FarOoOosa Aug 6 '12 at 9:12
    
I try it on seperate application and its work after change to 64 for platform target but how to work with that exception "Could not load file or assembly or one of its dependencies. An attempt was made to load a program with an incorrect format" –  FarOoOosa Aug 6 '12 at 9:15
add comment

9 Answers

Change the build options in your project: Platform target: any cpu.

Rebuild your project and you should be able to access it.

share|improve this answer
    
Changing "Platform target: any cpu." helped.. Thanks! –  user14822 Feb 11 '13 at 6:55
    
Thanks save my time! :) –  RedsDevils Sep 16 '13 at 6:32
add comment

All the answers which suggest logging in through the Admin account for development pose a serious risk because that is a very bad practice. You will rarely see a production environment which has been configured this way.

I will suggest that you give only the required privileges to the user with whom you are going to deploy your solutions.

share|improve this answer
add comment

I found that adding my user id to "WSS_ADMIN_WPG" did NOT fix the problem when in debug mode. I had to run Visual Studio 2010 in Administrator mode also.

share|improve this answer
add comment

I found that it works in a console application, but when I use this piece of code with an ASP.NET application it throws IO exceptions. Since there are some 32bit dlls referenced with my ASP.NET application, this creates a problem when I try to change to platform target of 64 bit.

For resolution, I created a separate service application running in a different process all the time. Luckily I had a scheduler kind of requirement so this workaround helped me.

share|improve this answer
add comment

try to executive your code by using SharePoint Admin account...

share|improve this answer
    
how to use that for admin account –  FarOoOosa Aug 6 '12 at 8:43
4  
Not very specific. Please improve this answer. –  Anders Rask Aug 6 '12 at 8:53
add comment

Please run the code from system administrator account if possible, otherwise add yourself to WSS_ADMIN_WPG group and ensure you are building the project with correct version i.e. 32-bit or 64-bit

share|improve this answer
add comment

close visual studio 2010, and open it again by right clicking on it and selecting “Run as Administrator".

share|improve this answer
    
are you sure this will work? because as i tried to do it in my system it didn't worked. –  Torque Oct 17 '12 at 11:59
add comment

change Platform Target to X64.

share|improve this answer
add comment

You need to run the application build as Any CPU, and add 2 references,

  • Microsoft.Office.Server.dll
  • Microsoft.SharePoint.dll

Both can be found in your ISAPI folder

Regards,
JP

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.