Unable to Add the App – The App domain for this site has already been assigned

Recently I was working on configuring SharePoint hosted apps for our customer and while testing I saw this issue.  After completing the configuration of Apps I uploaded an app to app catalog and added the app to a site. The app worked without any issue but there was one gotcha.  I missed to replace an S in App Prefix which was set to Apps so my app url was https://apps-1234.apps.contoso.com but the orignal plan was to use “app” as prefix. 

So I removed the app from the site and app catalog.  Then went to CA and changed the app prefix to app from “apps”.  Uploaded the test app to catalog and then tried to add to the site and it failed with error. “Unable to add the app to the site please retry”

I started ULS Viewer and started live log stream and clicked retry and saw an amazing message.  SharePoint app was still using “apps” while I have updated it app.  I knew something was goofy and traditionally UI is that good with me when it comes to SharePoint. 

SPException thrown: Message: The App domain for this site has already been assigned.. Stack:    at Microsoft.SharePoint.Utilities.SPUtility.ThrowSPExceptionWithTraceTag(UInt32 tagId, ULSCat traceCategory, String resourceId, Object[] resourceArgs) 

Here is what I did.
Open SharePoint Management Shell as administrator (Farm Account).

Set-SPAppDomain -AppDomain apps.contoso.com
Set-SPAppSiteSubscriptionName -Name "app" -Confirm:$false

#Open Command Prompt as Administrator. Run the commands below.
net stop sptimerv4
iisreset
net start sptimerv4
#Repeat the above 3 on all servers in the farm.

I closed all the browsers and opened the site and click Retry from Site content page.  Bingo the app was added without any problem.

Leave a comment