I have a requirement of configuring Search Navigation setting while Provisioning the site Collection.
Working fine in my local solution when I'm directly passing site collection to configure search settings.
But getting error if i configure along when i provision the site collection.
Getting the below error
| ERROR | Error occurred during ProvisionLibrary.ProvisionSiteCollection.ProvisioningSearchScope: Cannot invoke method or retrieve property from null object. Object returned by the following call stack is null. "GetNodeById Navigation " at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream) at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse() at ProvisionLibrary.ProvisionSiteCollection.ProvisioningSearchScope()
Here is my code
try
{
Log.Trace("Starting Search Scope Provisioning");
ClientContext oclientContext = new ClientContext(Context.Site.Url);
Web oweb = oclientContext.Web;
oclientContext.Load(oweb);
//oclientContext.Load(oweb.Navigation.GetNodeById(1040));
oclientContext.ExecuteQuery();
Log.Trace("Before Fetching Node"+ oweb.Url);
NavigationNode searchNavRoot = oweb.Navigation.GetNodeById(1040);
oclientContext.Load(searchNavRoot, root => root.Children);
oclientContext.ExecuteQuery();
Log.Trace("After Fetching Node" + oweb.Url);
// Get the navigation node collection.
//oclientContext.Load(searchNavRoot, root => root.Children);
Log.Trace("Before Fetching Children" + oweb.Url);
NavigationNodeCollection collNavigationNode = searchNavRoot.Children;
Log.Trace("After Fetching Children" + oweb.Url);
// Set properties for a new navigation node.
NavigationNodeCreationInformation ciNavicationNode = new NavigationNodeCreationInformation();
//SearchScopeList searchScope = new SearchScopeList();
//Log.Trace("Before loading scope" + Context.Site.Url);
//IList<SearchScopeList> SearchScopeColl = searchScope.LoadSearchScope(Context.Site.Url);
Log.Trace("Before Load external: " + oweb.Url);
ciNavicationNode.IsExternal = true;
ciNavicationNode.Title = "Test";
ciNavicationNode.Url = "Http://www.google.com";
collNavigationNode.Add(ciNavicationNode);
oclientContext.Load(collNavigationNode);
oclientContext.ExecuteQuery();
Please help