We have created site design/script that trigger a function app. The function app set’s some property bag values:

var adminCtx = ClientContextExtension.GetAppContext("https://xxx-admin.sharepoint.com", Configuration.AppRegistrationId, Configuration.AppRegistrationKey, Logger);
var tenant = new Tenant(adminCtx);
tenant.SetSiteProperties(Site.Context.Url, noScriptSite: false);

Logger.WriteTrace("Ownership found in DB. Setting propertybag values", SeverityLevel.Verbose);
Site.Context.Web.SetPropertyBagValue("forvaltning", KKOrg.Forvaltning);
Site.Context.Web.SetPropertyBagValue("afdeling", KKOrg.Afdeling);
Site.Context.Web.SetPropertyBagValue("kkorg", KKOrg.KKOrgNr);
Site.Context.ExecuteQueryWithIncrementalRetry(3, 5, Logger);

This works around 3 out of 4 times. Around 25% of the time this code does not set the values in property bag. Any ideas what can cause this? I can see in the logging the code is executed. Is it the site design kicking in to early and then being overriden or?


Did you write your own ExecuteQueryWithIncrementalRetry? What does that method look like? A faulty implementation of this pattern could result error hiding, i.e. no exception being thrown if max retries is reached.

Most implementations I've seen specify a delay in milliseconds. I'm assuming in your call that's the second argument or 5. 5 milliseconds is a pretty short delay, and probably not enough if you're being throttled by SharePoint online. Try bumping up that number and see if your results improve.

Ref: SPC059001: Consider implementing a pattern to avoid throttling with ClientContext.ExecuteQuery()

And in that example, they use 500 for the delay, or half a second.

  • I think it is an error in the tenant.SetSiteProperties(Site.Context.Url, noScriptSite: false). I have refactored the code so it set's this line first, and then do alot of other stuff, and then set the propertybag. That works. As stated in my custom implementation of the ExecuteQueryWithIncrementalRetry I have all kind of instrumentation and there is no errors thrown. So it is not related to any errors. I think it something with sitescripts to do. Some features in the site is simply not totally provisioned yet in the site when this trigger including the propertybag. Apr 14 '19 at 16:52

Try using ExecuteQueryAsync(), it permits a success and failure handler, e.g.:


Ensure that both the successHandler() and failureHandlers() are not reusable outside the ExecuteQueryAsync() method, hence the anonymous functions in the example below.


            function() {
            function() {

Documentation also See Here

  • Thanks for your reply. Your sample is javascript and mine is c#. I have a big try catch around it all, and there is no errors thrown. I suspect it to be sometjing about the timing with the site script/design. That the propertybag is being overriden by SPO, but not sure. As stated it works 3 out of 4 times. Apr 12 '19 at 6:05
  • The methods, members and concepts are all the same, here is the C# reference documentation for the same method. docs.microsoft.com/en-us/previous-versions/office/developer/… Apr 12 '19 at 11:28
  • What is your point around adding an event error handler? I have a try catch and can see no errors are thrown. Do you suspect this not to work? Apr 12 '19 at 11:43
  • Yes. I believe that when your code fails it is because it is attempting to perform a series of these ExecuteQuery but doing so synchronously. The code does not await any result from the ExecuteQuery method. It fires and forgets. By using ExecuteQueryAsync with success and failure handlers, by definition it is awaiting the completion of the query and determining if it failed or succeeded. Apr 12 '19 at 11:51
  • It doesn't need to wait for anything, because ExecuteQuery is synchronous. When it returns, the operation is complete, and if it fails it should throw an exception.
    – Joe McShea
    Apr 12 '19 at 14:10

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.