I try to instantiate an instance of SPSite
on the farm server in a custom process (MyApp.exe) and I give it as parameter the whole URI (http://mysite:80/). I also made sure that the account running MyApp.exe
is Site Collection Administrator
.
However, I can't make an instance of SPSite
whatever I am trying to do. It always throws a FileNotFoundException
.
Anyone got an idea?
StackTrace:
at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken)
at Microsoft.SharePoint.SPSite..ctor(String requestUrl) at MyCompanyName.Service.HelperClass.GetItemStateInSharePoint(SharePointItem item) in C:\Workspaces\MyCompanyName\Development\Main\MyCompanyName.SharePoint\Service\HelperClass.cs:line 555
Another side note... I have a Web Application + Site collection that I can access through the browser without any problem.
I had the same problem, I made below changes and it started working.
Changing the platform target in the build properties to x64 solved this issue for me on SharePoint 2010.
You can keep the project compilation target set to "Any CPU". The important this is to configure the MSTest host process to run in 64bits. Open your .testsettings file, go to Hosts tab and set "Run tests in 64 bit..."
If after this when you run your tests VS tells you there aren't any, remove and add your test project again (I don't know a better workaround for this)
Hope it helps!
I had the same issue. I wanted to run console application with my user id. I am web application owner + Farm Admin. Still was not able to run the application.
Issue was resolved by
Changing the platform target in build properties to x64
In site settings -->Users and Permissions --> Site Collection Administrators there were two names. Removed other name and it started working.
The MSTest on x64 issue was the cause of this problem for me. Works in a console app.
Switching to NUnit might not be an option for everyone.
In my case, the problem was that I was on a 64 bit server, I had Any CPU checked (so it was picking the correct version) but my Test Settings were set to "Force tests to run in 32 bit process" (GAH!)
In MSTest, Go to TEst->Edit Test Settings->Trace and Test Impact.
Choose Hosts.
Make sure you are running against the correct version.
Here is my checklist for VS2010 SP1, MSTest.