SPFarm.Local Object Being Cached in SharePoint 2013
-
10-12-2019 - |
Question
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?
Solution
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);
}
}