4

I am experiencing an odd issue where the SPFarm.Local object is not being updated for SharePoint 2013, but it does for 2010. Basically I have some code that adds/deploys/updates SharePoint solutions in C#. I have the thread wait until the solution is added and/or the deployment job is complete before continuing.

This is a simplified version of the code:

var complete = false;
while (!complete)
{
    complete = SPFarm.Local.Solutions[“solutionName.wsp”] != null;
    if (!complete)
        Thread.Sleep(10000);
}

In SharePoint 2010, this works perfectly. However, in 2013 the solution is continually returning null. I can verify the solution exists in a separate PowerShell window with Get-SPSolution, but it is not updating in this thread.

Any ideas on how to get SharePoint 2013 to update the SPFarm.Local object in the main thread?

  • how are you adding the solution? also see this thread: sharepoint.stackexchange.com/questions/42927/… – Mike Nov 6 '13 at 23:04
  • SPFarm.Local.Solutions.Add(path). This behavior also occurs when waiting for a solution to deploy (for the JobExists property to no longer be "true"). Something about 2013 is making the SPFarm.Local object not update. – John Chapman Nov 7 '13 at 0:03
  • 1
    I wonder if SPFarm.Update() afterwards would make a difference? – Mike Nov 7 '13 at 0:55
  • Trying that now. Will keep you posted. – John Chapman Nov 7 '13 at 2:30
  • That worked! Before making the thread sleep, I am updating the SPFarm. It works perfectly. Put that in an answer so I can mark it as such. – John Chapman Nov 7 '13 at 2:49
3

SP.Update() should work after you add the solution to the farm.

var complete = false;
while (!complete)
{
    complete = SPFarm.Local.Solutions[“solutionName.wsp”] != null;
    if (!complete){
        SPFarm.Local.Update();
        Thread.Sleep(10000);
       }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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