Feature Upgrade Error – SharePoint 2013 Migration

During our migration of MOSS 2007 content databases, we faced a unique issue during attaching the database to SharePoint 2013 (after the intermediate step of attaching to 2010).
We received below error for multiple site collections during upgrade.
Feature upgrade incomplete for Feature 'PremiumSite' (Id: 14/'8581a8a7-cf16-4770-ac54-260265ddb0b2') in Site ''. Exception: List does not exist.  The page you selected contains a list that does not exist.  It may have been deleted by another user.  (Inner Exception: List does not exist.  The page you selected contains a list that does not exist.  It may have been deleted by another user.0x81020026OWSSVR.DLL: (unresolved symbol, module offset=0000000000065F73)
 at 0x000007FCDF805F73 OWSSVR.DLL: (unresolved symbol, module offset=0000000000009468)
 at 0x000007FCDF7A9468 Microsoft.SharePoint.Library.ni.dll: (unresolved symbol, module offset=000000000009DA2C)
 at 0x000007FCE7FDDA2C Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000002B103FD)
 at 0x000007FCE43503FD Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000002B975B1)
 at 0x000007FCE43D75B1 Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000002B93800)
 at 0x000007FCE43D3800 Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000002AE8556)
 at 0x000007FCE4328556 )

We started digging around the ULS logs and found that the error is generated for a feature related to Access Services.

Feature Upgrade: Hidden activation dependency Feature 'AccSrvSolutionGallery' (Id: 14/'744b5fd3-3b09-4da6-9bd1-de18315b045d') could not be activated.  Exception: List does not exist.  The page you selected contains a list that does not exist.  It may have been deleted by another user..

Below is the stack trace for the error which we were able to capture after setting the diagnostic log settings to Verbose.

Feature receiver assembly 'Microsoft.Office.Access.Server.Application, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c', class 'Microsoft.Office.Access.Server.Template.SolutionGalleryFeatureReceiver', method 'FeatureActivated' for feature '744b5fd3-3b09-4da6-9bd1-de18315b045d' threw an exception: Microsoft.SharePoint.SPException: List does not exist.  The page you selected contains a list that does not exist.  It may have been deleted by another user. ---> System.Runtime.InteropServices.COMException: List does not exist.  The page you selected contains a list that does not exist.  It may have been deleted by another user.0x81020026OWSSVR.DLL: (unresolved symbol, module offset=0000000000065F73)
at 0x000007FCDF805F73 OWSSVR.DLL: (unresolved symbol, module offset=0000000000009468)
at 0x000007FCDF7A9468 Microsoft.SharePoint.Library.ni.dll: (unresolved symbol, module offset=000000000009DA2C)
at 0x000007FCE7FDDA2C Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000002B103FD)
at 0x000007FCE43503FD Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000002B975B1)
at 0x000007FCE43D75B1 Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000002B93800)
at 0x000007FCE43D3800 Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000002AE8556)
at 0x000007FCE4328556     
 at Microsoft.SharePoint.Library.SPRequestInternalClass.GetListsWithCallback(String bstrUrl, Guid foreignWebId, String bstrListInternalName, Int32 dwBaseType, Int32 dwBaseTypeAlt, Int32 dwServerTemplate, UInt32 dwGetListFlags, UInt32 dwListFilterFlags, Boolean bPrefetchMetaData, Boolean bSecurityTrimmed, Boolean bGetSecurityData, Boolean bPrefetchRelatedFields, ISP2DSafeArrayWriter p2DWriter, Int32& plRecycleBinCount)    
 at Microsoft.SharePoint.Library.SPRequest.GetListsWithCallback(String bstrUrl, Guid foreignWebId, String bstrListInternalName, Int32 dwBaseType, Int32 dwBaseTypeAlt, Int32 dwServerTemplate, UInt32 dwGetListFlags, UInt32 dwListFilterFlags, Boolean bPrefetchMetaData, Boolean bSecurityTrimmed, Boolean bGetSecurityData, Boolean bPrefetchRelatedFields, ISP2DSafeArrayWriter p2DWriter, Int32& plRecycleBinCount)     -
-- End of inner exception stack trace ---    
 at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)    
 at Microsoft.SharePoint.Library.SPRequest.GetListsWithCallback(String bstrUrl, Guid foreignWebId, String bstrListInternalName, Int32 dwBaseType, Int32 dwBaseTypeAlt, Int32 dwServerTemplate, UInt32 dwGetListFlags, UInt32 dwListFilterFlags, Boolean bPrefetchMetaData, Boolean bSecurityTrimmed, Boolean bGetSecurityData, Boolean bPrefetchRelatedFields, ISP2DSafeArrayWriter p2DWriter, Int32& plRecycleBinCount)    
 at Microsoft.SharePoint.SPListCollection.EnsureListsData(Guid webId, String strListName)    
 at Microsoft.SharePoint.SPListCollection.get_Count()    
 at Microsoft.SharePoint.SPSite.GetCatalog(SPListTemplateType typeCatalog, Boolean bWithEnum)    
 at Microsoft.Office.Access.Server.Template.SolutionGalleryFeatureReceiver.PerformFeatureOperation(Action`1 operation, SPFeatureReceiverProperties properties)    

 at Microsoft.SharePoint.SPFeature.DoActivationCallout(Boolean fActivate, Boolean fForce)

We were at a roadblock so we decided to take a look in the assembly Microsoft.Office.Access.Server.Application, we used a decompiler and found that the feature is trying to perform an operation on a list with id ‘121’.

ACCESSFEATURE

121 is the id for Access Solution Gallery and since we were migrating from 2007, there was no such list which was causing the failure.
Resolution: To fix the issue we activated publishing feature on all the site collections which created the list and then the upgrade was completed smoothly.
To activate the publishing feature:
Enable—SPFeature -Identity f6924d36-2fa8-4f0b-b16d-06b7250180fa —URL sitecollurl