Thursday, August 5, 2010

SharePoint 2010 SPSite : System.IO.FileNotFoundException

Can any one spot an error in the following snippet. Following snippet tries to open a SPSite, SPWeb and tries to open a List to get it item count. All objects exist in the server and this code was built with VS 2010 for SharePoint 2010 in x86 Debug mode.

I ended up with the following exception

System.IO.FileNotFoundException was unhandled
Message=The Web application at http://Foo 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.
Source=Microsoft.SharePoint
StackTrace:
at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken)
at Microsoft.SharePoint.SPSite..ctor(String requestUrl)
at ConsoleApplication1.Program.Main(String[] args) in C:\Users\Administrator\documents\visual studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:


After a couple of minutes I got things straight. There was a mistake in the build, as a basic rule while developing for SharePoint 2010 all your build should be in x64 mode not in x86 mode.

Basic mistake, but it hurts and the error message is not really helping...

1 comment:

Brian Esserlieu said...

Holly jeez. Your post about re-targeting the Visual Studio project to build on x64 vs x86 has just solved a problem I've been smashing my head on the wall over for the past 2 hours. Thank you so much!

If I'm the only one that didn't know this, I apologize, but here are the instructions to retarget from x86 (Visual Studio default) to x64:
right click the project -> properties -> (build tab) Platform target: (change to x64) -> save project -> (build project).