2

When developing provider hosted apps and testing in SharePoint Online, I've noticed that my AppInstalled remote event is often triggered 4 times when installing the app in site content. Here is an except from a log:

[07:47:38] ProcessEvent: AppInstalled
[07:47:54] ProcessEvent: AppInstalled
[07:48:04] ProcessEvent: AppInstalled
[07:48:10] ProcessEvent: AppInstalled

I suspect SPO thinks the installation somehow failed and therefore trying attempting to install it again. How can I stop this from happening? I tried using clientContext.RequestTimeout = Timeout.Infinite without success

2 Answers 2

0

You are correct that SP will retry 4 times if it fails to install/upgrade/uninstall. Have you checked to see if there are any errors being thrown from your Remote Event? There could be errors in generating ClientContext? A snippet of the code will help to diagnose?

If you do have errors, ensure you set the ErrorMessage and Status of the SPRemoteEventResult result = new SPRemoteEventResult(); before returning to SharePoint.

You can also propagate errors to the App Details page using the following code:

Microsoft.SharePoint.Client.Utilities.Utility.LogCustomRemoteAppError(ctx, productId, messageToLog);
ctx.ExecuteQuery();
5
  • No, it does not have to do with error being thrown. (It happens during normal execution. Another irritating situation is when debugging the code: Suppose I have a breakpoint, the debugger will sometimes trigger this breakoint several times, jumping back and forth between two or more threads being debugged at the same time.)
    – rlv-dan
    Oct 9, 2014 at 10:05
  • It might be a bit easier to diagnose with a code snippet to show us? Because what you are describing is exactly what would happen as a result of an exception...
    – z.rahui
    Oct 10, 2014 at 0:04
  • I understand, but the code in question is hundreds, perhaps thousands of lines so it's not possible. A lot of it is based on PnP for best practice, and exceptions are handled. I'm pretty sure the problem is not an exception, because I can follow the code flow both using the debugger and my logs, and there I can see that new calls are made even though old calls are still running.
    – rlv-dan
    Oct 10, 2014 at 4:57
  • Being "thousands of lines of code", could the request be timing out and so SharePoint tries to call the service endpoint again? Maybe try to increase the executionTimeout value in the Web.Config of your Remote Web?
    – z.rahui
    Oct 10, 2014 at 5:01
  • Thanks for the suggestion, but after setting executionTimeout to 300, I could still see in the logs that a new call was made only 30 seconds after the initial one.
    – rlv-dan
    Oct 10, 2014 at 11:12
0

I have yet to find any good solution to this problem. Some suggest intercepting events and cancel/halt them until the first call is finished. While I was able to use this technique while developing, it causes other problems though, especially with communicating back to SharePoint if the app was properly installed or not. Thus I do not find it an acceptable solution for production.

I decided to remedy the situation by moving the (time expensive) provisioning code from the AppInstall event into a button on the App's page. The user will first have to install the app, then open the app and manually click the button to complete the installation. From a user experience point of view this is not as good, but it seems to be the most proper way to do this for now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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