Question

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

Was it helpful?

Solution 2

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.

OTHER TIPS

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top