Wednesday, 15 June 2011

Diagnose MissingSetupFile issues from the SharePoint Health Analyzer using PowerShell

A couple of weeks back I posted an article on how to remove missing features from a content database when you receive the [MissingFeature] error in the SharePoint Health Analyzer. I have since received quite a few requests on how to resolve the [MissingSetupFile] error, which also appears in the Health Analyzer under the “Configuration” category with the title “Missing server side dependencies”:

Missing server side dependencies

The error message reported will look similar to this one:

[MissingSetupFile] File [Features\ReviewPageListInstances\Files\Workflows\ReviewPage\ReviewPage.xoml] is referenced [1] times in the database [SharePoint_Content_Portal], but is not installed on the current farm. Please install any feature/solution which contains this file. One or more setup files are referenced in the database [SharePoint_Content_Portal], but are not installed on the current farm. Please install any feature or solution which contains these files.

Easily the best way of resolving these issues is to do as the error suggests and install the missing feature or solution, but if this is not possible or feasible to do in your scenario, there are some ways of using PowerShell to locate the source of the error in the content database and act on it accordingly.

There isn’t really a silver bullet to resolving the issue in all cases as the error could be referring to themes, files, workflows, web parts, and more. The key here is to find the file that references the missing setup file and then deal with it appropriately. Since we don’t know which site contains the file from the error message reported in the Health Analyzer, the best way I have found to diagnose the issue is to examine the content database using a SQL query in order to locate the file reporting the problem.

To help with this, I have adapted a PowerShell script from “Jelly” in this article (thanks Jelly) and created the following function:

function Run-SQLQuery ($SqlServer, $SqlDatabase, $SqlQuery)
{
    $SqlConnection = New-Object System.Data.SqlClient.SqlConnection
    $SqlConnection.ConnectionString = "Server =" + $SqlServer + "; Database =" + $SqlDatabase + "; Integrated Security = True"
    $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
    $SqlCmd.CommandText = $SqlQuery
    $SqlCmd.Connection = $SqlConnection
    $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
    $SqlAdapter.SelectCommand = $SqlCmd
    $DataSet = New-Object System.Data.DataSet
    $SqlAdapter.Fill($DataSet)
    $SqlConnection.Close()
    $DataSet.Tables[0]
}

After you have loaded the function in a PowerShell console, you can run it by using the Run-SQLQuery command with the options relevant to your deployment. For [MissingSetupFile] errors, you need to run a SQL SELECT query on the “AllDocs” table in the content database exhibiting the problem. For example, you would type the following command to examine the location of the “Features\ReviewPageListInstances\Files\Workflows\ReviewPage\ReviewPage.xoml” file reported in the [MissingSetupFile] error at the top of this article:

Run-SQLQuery -SqlServer "SQLSERVER" -SqlDatabase "SharePoint_Content_Portal" -SqlQuery "SELECT * from AllDocs where SetupPath = 'Features\ReviewPageListInstances\Files\Workflows\ReviewPage\ReviewPage.xoml'" | select Id, SiteId, DirName, LeafName, WebId, ListId | Format-List

To run this in your environment, replace “SQLSERVER” with the name of the SQL server hosting your content databases, “SharePoint_Content_Portal” with the name of the content database, and the file path in the SELECT query with the path of the missing setup file reported in the Health Analyzer (make sure this file path is enclosed in single quotes as shown above).

When the script is run, it will produce an output similar to the text below:

Id       : f5fc66e7-920a-4b44-9e3d-3a5ab825093f
SiteId   : 7b4d043c-8bbe-4068-ad91-3c270dfae151
DirName  : subsite/Workflows/Review Page
LeafName : Review Page.xoml
WebId    : 1876be06-419f-46fb-a942-a15e510f1a70
ListId   : a04dda01-a52d-4d5b-b3b4-fcd70a05e4ba

Now we have the SiteId and WebId, we can use them in a few lines of PowerShell script to display the URL of the site containing the problem file:

$site = Get-SPSite -Limit all | where { $_.Id -eq "7b4d043c-8bbe-4068-ad91-3c270dfae151" }
$web = $site | Get-SPWeb -Limit all | where { $_.Id -eq "1876be06-419f-46fb-a942-a15e510f1a70" }
$web.Url

In case it isn’t clear from the “DirName” value reported from the SQL query output, you can also use PowerShell to get the URL of the actual file causing the issue by calling the “Id” field of the item:

$file = $web.GetFile([Guid]”f5fc66e7-920a-4b44-9e3d-3a5ab825093f”)
$file.ServerRelativeUrl

Now you have to decide what to do with the offending file. In the case of the error I reported at the top of this article, the file came from a workflow deployed to the site using a feature, which was not deactivated from the site prior to removing the solution from the farm. Therefore, to solve the issue I just used SharePoint Designer to remove the workflow from the site. In the case of web parts, removing web parts from the page reported in the Health Analyzer may solve the issue. Once you have dealt with the problem file, you should now be able to reanalyse the “Missing server side dependencies” issue in the Health Analyzer to clear the problem.

Please note that if you do decide to delete a workflow or a file from the site, remember to remove the file from the site Recycle Bin and Site Collection Recycle Bin to ensure the file is removed from the content database. If not, the error may not disappear from the Health Analyzer.

If you found this article looking for information on how to diagnose MissingFeature issues in the SharePoint Health Analyzer, rather than the MissingSetupFile issue, then have a look at this article for help. For information on troubleshooting MissingWebPart and MissingAssembly errors, take a look at this article.

37 comments:

  1. Really great article !

    I have created an automated script based on your input.
    http://etienne-sharepoint.blogspot.com/2011/10/solving-missingsetupfile-errors-from.html

    Thanks again Phil.

    ReplyDelete
  2. So, I get the 'MissingSetupFile' message a lot, related to one of my custom solutions that was once deployed on a sub-site that has now been totally obliterated. Thus, the $WebId variable that I get returned from the SQL query is always 00000000-0000-0000-0000-000000000000

    (was also getting this for EventReceivers)

    Is it safe to just delete the records from the AllDocs table or the EventReceivers tables if the WebId is blank?

    ReplyDelete
  3. Helped me a lot. Thanx so much.

    ReplyDelete
  4. Following your steps, I have removed all offending files from Sharepoint designer and reanalyze, but the message still exists in Health Analyzer.
    Does anything I can do to remove the message? Thanks.

    ReplyDelete
  5. Similar issue as Ar Paul. What's the theory on when the changes are applied? Timer job? Re-attach content database?

    SharePointWarrior

    ReplyDelete
  6. Hi,

    It's nice article. I have followed the steps as mentioned. But when I try to delete the masterpagefile, I was getting an error "This item cannot be deleted because it is still referenced by other pages". In this scenario, how do I remove those references before deleting the master page? Please help me on this.

    -Prakash

    ReplyDelete
  7. what if the page/web, which referencing missing setup file, is also missing?

    ReplyDelete
  8. Just FYI: As with the last poster, there is a reference in a missing file on one and the other is the site home page which does not at all reference the deleted webpart. At this point I'm going to have to throw in the towel on this one and just ignore this error until I have more time to come back and revisit it. However if this helps anyone diagnose the issue, I created a custom web part in VS2010 to fish data out of an external data source and render it on the home page. Because I had no dev environment and this new instance of SharePoint is currently pre-migration, I have been testing the web part on the production server. Regardless of anyone's opinion on dev best practices, this was my only option. As such, I had to test, observe results, and then modify to correct issues on my production server. Part of that process was retracting/uninstalling the web part and then redeploying.

    I also renamed the webpart at one point and redeployed. I think this is where the problem began. Currently I can redeploy the web part under the old name and it will resolve the problem, but it will leave an unusable web part in my web part gallery. This is not acceptable. So I would just end up retracting/uninstalling the web part, and then deleting the .webpart file from the web part gallery which will only result in the same error.

    I followed the instructions of this article all the way up to $file.ServerRelativeUrl. Unfortunately, nothing is returned. There simply is no file to reference.

    Trying to find anything regarding the mention of my old web part in the site file (which has to be home.aspx, the only file I was modifying), I ran the SQL Query from the Missing Web Part article and confirmed that it's indeed referenced by the SitePages/Home.aspx file. However, this isn't true at all. The webpart was deleted from that web page.

    Id :
    SiteId :
    DirName :
    LeafName :
    WebId :
    ListId :
    tp_ZoneID :
    tp_DisplayName :

    Id : b0235deb-5dc2-4043-90d4-3d4c016d8228
    SiteId : 806c2cee-ca06-4b6c-889c-479a6f215fff
    DirName : SitePages
    LeafName : Home.aspx
    WebId : 36b7368f-b2a9-4f8b-a0bf-7f2bb25baa4a
    ListId : da989695-227d-497a-847e-111c984f848a
    tp_ZoneID : wpz
    tp_DisplayName :

    Feel free to follow up on this if anyone finds a viable solution. In the meantime, I'll be ignoring the alert. :(

    ReplyDelete
    Replies
    1. Maybe there was a version of the home page still having the web part. Check for versions and delete them.

      Delete
  9. Curious to know if anyone received this error in the powershell console after loading the initial function:

    The term 'Run-SQLQuery' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if
    a path was included, verify that the path is correct and try again.

    ReplyDelete
  10. This and your other dependency resolution scripts were very helpful to me. Thanks again!

    ReplyDelete
  11. Thanks Phil.

    This is an excellent article and it works with 100% accuracy.

    ReplyDelete
  12. Thanks for this series of articles - they have helped greatly.

    I am down to one remaining issue, which appears to be a feature in Central Admin that is broken.

    MissingSetupFile] File [Features\SPPPlatformAdminSite\SPP.aspx] is referenced [1] times in the database [SharePoint_AdminContent_7ae3762e-394a-48e2-9f02-beecaf3ed4c1], but is not installed on the current farm. Please install any feature/solution which contains this file. One or more setup files are referenced in the database [SharePoint_AdminContent_7ae3762e-394a-48e2-9f02-beecaf3ed4c1], but are not installed on the current farm. Please install any feature or solution which contains these files.

    The scripts above don't seem to work the same on the Central Admin site. Any suggestions on how to clean this one up?

    ReplyDelete
  13. I find myself using this post time and time again. Seeking this article at the top of Google results--it should be! (Maybe I should just bookmark it.)

    As you mentioned--and as a reminder to others--don't forget to delete the item or site from the recyle bins so it is permanently gone. This includes the end user recycle bin (labelled "End user Recycle Bin items") and the admin recycle bin (labelled "Deleted from end user Recylce Bin"). Otherwise, it's still there in the content DB and many tests (Health Analyzer and Test-SPContentDatabase) will still understand the need for the feature or setup file (what if you were to restore from the recycle bin?).

    ReplyDelete
  14. Thank you! These scripts have helped me clean up issues that have been hanging around for months! I can apply CUs again and have a shot at completing them.

    ReplyDelete
  15. It's a pleasure, Eric. Glad they have been helpful for you

    @spsawyer - definitely worth reiterating that one!

    ReplyDelete
  16. Warning: This is directly querying the Sharepoint SQL database which can put your database in an unsupported state.

    ReplyDelete
  17. The statement from Microsoft on this only considers the database in an unsupported state if SQL queries are identified as a "barrier to the resolution of a Microsoft support engagement". It then goes on to say that the database can be returned to a supported state if these read activities are stopped. http://support.microsoft.com/kb/841057

    These scripts run SELECT statements only and do not write back to databases, which would definitely be unsupported. They are also not intended to be run as a scheduled or "business as usual" operation.

    ReplyDelete
  18. Can someone please provide me script for removing the missing setup files from multiple sites. It would be really appreciated

    ReplyDelete
  19. I am able to find the affected sites using the Site ID and Web Id , however I don't understand how to fix the missing setup error . Please advise.

    ReplyDelete
  20. I am getting the below result after running the query for webpart missing setup file. Its pointing tot he webpart file it self?

    Can someone please help?

    Id :
    SiteId :
    DirName :
    LeafName :
    WebId :
    ListId :

    Id : 0a81d151-2a1a-448b-80b2-1dd252656858
    SiteId : ddcfdf57-5fe2-4d12-933b-47e0ce437edb
    DirName : _catalogs/wp
    LeafName : FunImageSlider.webpart
    WebId : ce7cb651-6677-4a4c-a82c-bade921b7853
    ListId : 05d2978c-2e26-4a57-b27b-8bda3c578652

    ReplyDelete
    Replies
    1. This post is about MissigSetupFile error
      See this link for MissingWebPart error : http://get-spscripts.com/2011/08/diagnose-missingwebpart-and.html
      regards

      Delete
  21. I am getting the below message on the server side dependencies.

    Could you please guide me which script do i need to run to fix this? I have tried both MissingFile & no success.

    [MissingSetupFile] File [Features\FunImageSlider_Feature2\FunImageSlider\FunImageSlider.webpart] is referenced [1] times in the database [SharePoint_Content_Database], but is not installed on the current farm. Please install any feature/solution which contains this file. One or more setup files are referenced in the database [SharePoint_Content_Database], but are not installed on the current farm. Please install any feature or solution which contains these files.

    [MissingSetupFile] File [Features\FunImageSlider_Feature2\ImagesFarm\arrows.png] is referenced [1] times in the database [SharePoint_Content_Database], but is not installed on the current farm. Please install any feature/solution which contains this file. One or more setup files are referenced in the database [SharePoint_Content_Database], but are not installed on the current farm. Please install any feature or solution which contains these files.

    ReplyDelete
    Replies
    1. Output of MissingSetup file is below.

      Id :
      SiteId :
      DirName :
      LeafName :
      WebId :
      ListId :

      Id : 0a81d151-2a1a-448b-80b2-1dd252656858
      SiteId : ddcfdf57-5fe2-4d12-933b-47e0ce437edb
      DirName : _catalogs/wp
      LeafName : FunImageSlider.webpart
      WebId : ce7cb651-6677-4a4c-a82c-bade921b7853
      ListId : 05d2978c-2e26-4a57-b27b-8bda3c578652

      Delete
  22. A special thanks for this informative post. I definitely learned new stuff here I wasn't aware of !

    ReplyDelete
  23. Good post, thanks!
    Took me a while (I'm ashamed to say how long) to figure out why I kept on receiving this error, and after running the SQLquery all I got was blanks:

    PS C:\Users\sp_install> Run-SQLQuery -SqlServer -SqlDatabase -SqlQuery "SELECT * from AllDocs where SetupPath = 'Features\ReviewPageListInstances\Files\Workflows\ReviewPage\ReviewPage.xoml'" | select Id, SiteId, DirName, LeafName, WebId, ListId | Format-List

    Id :
    SiteId :
    DirName :
    LeafName :
    WebId :
    ListId :

    In the end, what solved it for me, is to navigate to the recycle bin in Central Admin, and removing all files deleted by end users (the second stage recycle bin)...

    Oh well, you live, you learn...

    ReplyDelete
  24. تعد شركة البيت الافضل افضل الشركات العامة في الخدمات المنزلية تقدم افضل الخدمات باعلى جودة وباقل الاسعار
    شركة تخزين عفش بالرياض
    شركة نظافة بالرياض
    شركة غسيل خزانات بالرياض
    شركة مكافحة الحشرات بالدمام
    بالاضافة الى خدماتنا الاخرى مثل :
    شركة شراء اثاث مستعمل بالرياض
    كشف تسربات المياه بالرياض
    شركة تنظيف بيوت بالرياض
    ونتميز في جميع الخدمات بان اسعارنا تعد ارخص الاسعار بالمقارنة مع الشركات الاخرى
    شركة نقل عفش بالرياض
    رش مبيدات بالرياض
    شركة مكافحة الحشرات بالرياض
    افضل شركة تنظيف مجالس بالرياض

    ReplyDelete
  25. - بق الفراش
    يحتاج الى مكافحة متخصصة لانها حشرة عنيدة وتختبأ في اماكن يصعب الوصول اليها ويحتاج الى رش المنزل واحيانا المنازل المجاورة لضمان عدم تواجدها في محيط المنزل ومعادة الاصابة بها الاول تستخدم افضل مبيدات مكافحة بق الفراش وتضمن لك القضاء النهائي عليه فالاول تعرف بانها اشهر شركة مكافحة البق بالرياض واشهر شركة مكافحة البق بجدة واشهر شركة مكافحة البق بمكة
    شركة مكافحة بق الفراش بجدة
    شركة مكافحة العته بمكة
    شركة مكافحة البق بالمدينة المنورة
    شركة مكافحة البق بالاحساء وشركة مكافحة البق بالخبر و شركة مكافحة البق بالخرجو شركة مكافحة البق بابها و شركة مكافحة البق بالقصيم و شركة مكافحة البق بينبع
    وافضل شركة مكافحة البق بالجبيل

    ReplyDelete