0

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

0

Can you please use the below code and check the result :

          using (ClientContext Context = new ClientContext("Site URL"))
        {
            SecureString password = CreateSecurePassword("password");
            Context.Credentials = new SharePointOnlineCredentials("username", password);                
            Web oWeb = Context.Web;

            Context.Load(oWeb);
            //oclientContext.Load(oweb.Navigation.GetNodeById(1040));
            Context.ExecuteQuery();

            NavigationNodeCollection searchNavRoot = oWeb.Navigation.GetNodeById(1040).Children;
            Context.Load(searchNavRoot);
            Context.ExecuteQuery();
            // Get the navigation node collection.
            //oclientContext.Load(searchNavRoot, root => root.Children)


            // Set properties for a new navigation node.
            NavigationNodeCreationInformation searchNav = new NavigationNodeCreationInformation();

            searchNav.IsExternal = true;
            searchNav.Title = "Test";
            searchNav.Url = "Http://www.google.com";
            searchNavRoot.Add(searchNav);
            Context.Load(searchNavRoot);
            Context.ExecuteQuery();
        }

I hope this helps. Don't forget to upvote and mark it as answer if this resolves your issue.

  • I tried this also getting the same error, This code works fine if i'm running from my local project. If I configure the Search Navigation settings while provisioning the site collection then this is error 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() – user3094601 Sep 26 '18 at 9:35
  • How are you applying these changes, While provisioning is in process or after provisioning of site is completed ?. In First scenario, it will not be able to create the object of site and In second scenario, I will suggest to wait for 10 minutes before proceeding with these changes. If possible please give the complete code for a better understanding. – Ravi Sep 27 '18 at 7:31

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.