Tuesday, October 26, 2010

SP 2010 SPSite FileNotFoundException

SPSite site = new SPSite("http://domainname/sites/sc");

is a frequently used statement to open a site collection on a SP server, particularly from a separate application (Console App, ASP.NET app) to look inside the SharePoint. A frequently encountered problem is that it throws a FileNotFoundException:

"The Web application at http://domainname/sites/sc could not be found. Verify that you have typed the URL correctly. "

Of course the URL is correct. In a SP 2010 dev environment, you'll almost inevitably run into this the first time. What the problem is, SP 2010 is 64 bit only. And by default, Visual Studio compiles your Console, WinForm, Asp.Net projects in 32 bit. So you need to change it: Go to the project Properties -> Build -> Platform target, change to either either x64 or Any CPU. Build again, and the error goes away.

MOSS 2007 64 bit would cause this problem too but since developers often install 32 bit for dev purpose, it's encountered less frequently.

Monday, October 25, 2010

Failed to create field: Field type myfield is not installed properly

You have seen this error in MOSS 2007 and it's the same in SP 2010:

"Failed to create field: Field type is not installed properly. Go to the list settings page to delete this field."

This can happen when you activate or deactivate a feature that includes this field. The message is not helpful. There are plenty of discussions about this and apparently a gazillion scenarios that this could occur. In my case, it's because myfield is a custom field inherited from SPFieldMultiColumn. And I didn't include the class (and the assembly) in the deployment. Hence when it goes to create or delete the field, there's nothing other than the metadata in the XML field definition.

So at least one scenario cleared up.