This is one of those silly little mistakes which we very often overlook…and believe it or not, I have found many forums and blog posts where developers ask for help on this.
I wanted to work with the SPFarm.Local object earlier this week and forgot that SharePoint 2010 targets the 64bit platform …duh… so when I tried the following code:
private void cmdCreateWebApp_Click(object sender, EventArgs e)
{
int myPort = 999;
SPFarm farm = SPFarm.Local;webAppBuilder.Port = myPort;
SPWebApplicationBuilder webAppBuilder = new SPWebApplicationBuilder
(SPFarm.Local);
SPWebApplication newApplication = webAppBuilder.Create();
newApplication.Provision();
SPSite mySiteCollection = newApplication.Sites.Add("/",
@"Mydomain\MyAdminUserName", "MyAdminUserEmail@CompanyName.co.za");
mySiteCollection.Close();
}
I kept getting an exception and found that SPFarm.Local remains null.
The problem was that my VS2010 project was set to target a x86 platform and not the x64!!
So, I opened my project properties and changed the platform target to x64.
Recompiled my code and ran it and it worked like a charm !
Always remember guys…. X64 !!!!!
0 comments:
Post a Comment