3

I have a Provider-Hosted SharePoint app with an appmanifest.xml that looks something like this:

<Properties>
  <Title>My app title</Title>
  <StartPage>
    ~remoteAppUrl/home/index?{StandardTokens}
  </StartPage>
  <InstalledEventEndpoint>
    ~remoteAppUrl/Services/AppEventReceiver.svc
  </InstalledEventEndpoint>
  <UpgradedEventEndpoint>
    ~remoteAppUrl/Services/AppEventReceiver.svc
  </UpgradedEventEndpoint>
  <UninstallingEventEndpoint>
    ~remoteAppUrl/Services/AppEventReceiver.svc
  </UninstallingEventEndpoint>
</Properties>

I am publishing the app by adding it to the app catalog and then adding it to a site, I am not side-loading it from Visual Studio. When the app is installed or upgraded, the ProcessEvent method from the AppEventReceiver class is invoked.

However, when the app is removed from the site, the ProcessEvent method from the AppEventReceiver class is NOT invoked. I have tried something like this:

public class AppEventReceiver : IRemoteEventService
{
    public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
    {
        var result = new SPRemoteEventResult();
        switch (properties.EventType)
        {
            case SPRemoteEventType.AppUpgraded:
            case SPRemoteEventType.AppInstalled:
                Trace.WriteLine("App is being installed or upgraded...");
                break;
            case SPRemoteEventType.AppUninstalling:
                Trace.WriteLine("App is being uninstalled...");
                break;
        }
        return result;
    }
}

The app is published to an azure website. When I turn on Verbose logging and watch the log streams, I can see:

Application: 2014-12-09T13:11:35  PID[1972] Verbose     App is being installed or upgraded...

However when removing the app, I never see any log messages. Also, I can attach a remote debugger and step through the code when the app is installed or upgraded. When removing the app, my breakpoints are never hit.

What gives?

  • Did you try to remove it from recycle bin? – sjkp Dec 14 '14 at 0:41
7
+50

I faced the similar issue. In my case, I went to Site Settings -> Recycle Bin removed the app from there and then went to second stage recycle bin and deleted from there as well. After that, the event receiver fired.

enter image description here

  • 1
    ^This is the correct answer. The event does not fire until the App has been removed from the Second Stage recycle bin. – z.rahui Dec 19 '14 at 4:05
  • 1
    Perfect, sounds like this is the answer I was looking for. I will come back to mark as answer and reward bounty as soon as I can test. Thanks! – danludwig Dec 19 '14 at 17:35
1

When the app is uninstalled we’re also removing the event receiver. In order to make this work during debugging you’ll need to ensure that you navigate to the “Apps in testing” library and use the remove option on the app. This remove will trigger the app uninstalling event with the proper permissions to remove the created remote event handler. If you just close the browser or uninstall the app from the “site contents” then either the event receiver never fires or the event receivers runs with unsufficient permissions to remove the list added event receiver. The reason for this behavior is differences in app deployment when the app gets side loaded which is what Visual Studio does when you press F5.

When a user uninstalls a deployed app this moves the app to the site's recycle bin and will NOT trigger the appuninstalling event handler. The app needs to be removed from all recycle bins in order to trigger the appuninstalled event.

Ref: https://github.com/OfficeDev/PnP/tree/master/Scenarios/Core.EventReceiversBasedModifications

Hope it helps! Thanks, Avni Bhatt

0

Make sure following properties are set to True

enter image description here

  • All 3 of these are set to true. Note the appmanifest.xml in the OP. – danludwig Dec 17 '14 at 1:22
  • @danludwig was this app sideloaded? If yes then try normal deploy & removal process. Also check this working solution blogs.msdn.com/b/kaevans/archive/2014/02/26/… – Amal Hashim Dec 17 '14 at 1:55
  • Amal, please read the OP. No, the app is not being sideloaded. – danludwig Dec 17 '14 at 13:18

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.