The solution is not a permanent solution. I am able to delete it with the script provided. But i still cannot redeploy my solution from VisualStudio. Is there a way to get this working or do i need to keep deleting it with the script?

I'm trying to deploy a Sharepoint online add-in that i created with visual-studio 2015. After the first deploy i try to deploy it a second time and i'm not able to do this.

I get the error messages:

SharePoint Add-in is in an invalid state and cannot be uninstalled.

When i couldn't uninstall the add-in that way i tried to delete it from the browser "Site content" i could not see the option to do this. Switching to the classic version i got the option. Still i'm not able to delete it.

If i click "Click to retry." it is not able to delete it.

I'm Site Collection Administrators.

What could it be?


To resolve this problem you need to remove your SharePoint Add-In by PowerShell so the following script demonstrate how to Uninstall SharePoint Add-in in SharePoint Online:

Note : You must have SharePoint Online Client Components SDK installed on the system.


Function Get-ClientContext([string]$Url,[string]$UserName,[string]$Password)
    $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
    $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
    $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
    return $context

Function Uninstall-AppInstance([Microsoft.SharePoint.Client.ClientContext]$Context,[Guid]$AppInstanceId)
    $appInst = $Context.Web.GetAppInstanceById($AppInstanceId)

$UserName = "jdoe@contoso.onmicrosoft.com"
$Password = Read-Host -Prompt "Enter the password"    
$Url = "https://contoso.sharepoint.com/"
$AppInstanceid = New-Object Guid("XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")  #specify App Instance Id here

$context = Get-ClientContext -Url $Url -UserName $UserName -Password $Password
Uninstall-AppInstance -Context $context -AppInstanceId $AppInstanceid

How to get App Instance Id

  1. Go to your SharePoint Add-in then try click the ellipses (...) beside the application like image below then click DETAILS : enter image description here

Once the detail page will be opened, App Instance Id could be grabbed from Url :


  • This i understand. But this gives me another question. Is it possible to create an app and deploy it to my SharePoint developer site? And redeploy it without using the script every time? I forgot to mention it is a developer site of SharePoint online. – luc schmeits Sep 14 '17 at 6:44
  • Normally you can just by redeploying your SharePoint Add-In by Visual Studio . The Error that you getting here is an Expected Error the only way to resolve it is executing this script to remove it then you can continue deployment normally. – Youssef Moumen El idrissi Sep 14 '17 at 8:18
  • I'm not able to let visualstudio delete it. Any ideas what could be the problem? The script worked! (Thanks) – luc schmeits Sep 14 '17 at 8:20
  • You are welcome If it's removed now try to redeploy it by visual studio again. – Youssef Moumen El idrissi Sep 14 '17 at 8:26
  • Yeah that works. The problem is that i always will need to run the script to delete the app.(i can not deploy a second time) This because i'm not able to delete the app from Visual Studio. Do you know if there is a solution so i can let visual studio uninstall the app and install the new version? – luc schmeits Sep 14 '17 at 9:49

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.