• Error Missing Assembly en el Health Analyzer

    Uno de los hallazgos más comunes en el Health Analyzer, cuando se desarrollan soluciones a la medida en SharePoint 2010 es el siguiente:

     

    Assembly [My.Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cfc9a4dcd383ae1e] is referenced in the database [WSS_Content], but is not installed on the current farm. Please install any feature/solution which contains this assembly.

     

    La mayoría de las veces el hallazgo es acerca de Recibidores de Eventos que no han sido correctamente desinstalados, ya sea en la desactvación o eliminación de la solución.

     

    En esta entrada de blog pretendo compartir con ustedes un script de Power Shell con el don de ayudar a identificar y remover estos Recibidores de Eventos corruptos.

     

    El script contiene las siguientes funciones:

     

    Delete-MissingAssembly: Esta es la función principal que recorre cada posible contenedor en la base de datos que pueda tener Recibidores de Eventos, esto quiere decir Colección de listas, Sitios o Listas.

     

    Remove-EventReceiver: Esta función revisa si un contenedor de Recibidores de Eventos tiene alguno con el nombre de assembly que se le pase como parámetro, y trata de eliminarlo.

     

    Las 2 funciones tienen un parámetro (ReportOnly) que permite definir si se quiere eliminar o no el Recibidor de Evento encontrado.

     

    function Delete-MissingAssembly($ContentDb, $Assembly, [switch]$ReportOnly)

    {

           [bool]$report = $false

           if ($ReportOnly) { $report = $true }

           $database = Get-SPContentDatabase | ?{$_.Name -eq $ContentDb}

        foreach($site in $database.Sites)

        {

            Remove-EventReceiver -ERContainer $site -Assembly $Assembly -ReportOnly $report

            foreach($web in $site.AllWebs)

            {

                Remove-EventReceiver -ERContainer $web -Assembly $Assembly -ReportOnly $report

                foreach($list in $web.Lists)

                {

                    Remove-EventReceiver -ERContainer $list -Assembly $Assembly -ReportOnly $report

                }

            }

        }

    }

     

    function Remove-EventReceiver($ERContainer, $Assembly, $ReportOnly)

    {

        foreach($er in $ERContainer.EventReceivers)

           {

                 if($er.Assembly -eq $Assembly)

                 {

                        Write-Host "Event Receiver with Id[" $er.Id "], Name[" $er.Name "] and Type [" $er.Type "] found in [" $ERContainer.Url $ERContainer.DefaultViewUrl "]."

                        if($ReportOnly -eq $false)

                        {

                    Write-Host "Try to delete the receiver:"   

                    $er.Delete()

                    Write-Host "ER deleted."

                        }

                 }

           }

    }

     

     

    Después de que usted guarde este script en un archivo PS1 y lo importe en Power Shell (Ejemplo: Import-Module .\MissingEV.PS1), usted puede ejecutar el script de esta forma:

     

    Delete-MissingAssembly -ContentDb WSS_Content -Assembly "My.Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cfc9a4dcd383ae1e" -ReportOnly

     

    La salida de ejecución del comando puede ser:

     

    Como se puede ver en la salida de Power Shell, muestra el Id, Nombre, Tipo y ubicación del Recibidor de Eventos, donde usted puede decidir si borrar o no este, por lo contrario debería utilizar otra herramienta o directamente con PS.

     

    Espero que esta entrada sirva para resolver los típicos problemas del hallazgo “Missing server dependencies” en el Health Analyzer.

     

  • MissingAssembly Error in Health Analyzer

    One of the most common issues in the Health Analyzer when you deploy custom solutions in your SharePoint 2010 environment, is this one:

     

    Assembly [My.Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cfc9a4dcd383ae1e] is referenced in the database [WSS_Content], but is not installed on the current farm. Please install any feature/solution which contains this assembly.

     

    Most of the times this issue is regarding some bad Event Receivers that you forgot to remove before you delete the custom solution, or another problem related with the feature deactivation and solution retraction.

     

    In this post I want to share with you a Power Shell script that can help you to remove this kind of bad Event Receivers.

     

    The following script contains 2 functions:

     

    Delete-MissingAssembly: This is the main function that goes through every possible container in the specific database that can host an Event Receiver, it means Site, Web or List.

     

    Remove-EventReceiver: This function check if the event receiver container has any event receiver with the specific assembly name, shows his information and try to delete it.

     

    Also the 2 functions has a parameter to allow directly delete the event receiver or only shows in the screen the information regarding the ER.

     

     

    function Delete-MissingAssembly($ContentDb, $Assembly, [switch]$ReportOnly)

    {

           [bool]$report = $false

           if ($ReportOnly) { $report = $true }

           $database = Get-SPContentDatabase | ?{$_.Name -eq $ContentDb}

        foreach($site in $database.Sites)

        {

            Remove-EventReceiver -ERContainer $site -Assembly $Assembly -ReportOnly $report

            foreach($web in $site.AllWebs)

            {

                Remove-EventReceiver -ERContainer $web -Assembly $Assembly -ReportOnly $report

                foreach($list in $web.Lists)

                {

                    Remove-EventReceiver -ERContainer $list -Assembly $Assembly -ReportOnly $report

                }

            }

        }

    }

     

    function Remove-EventReceiver($ERContainer, $Assembly, $ReportOnly)

    {

        foreach($er in $ERContainer.EventReceivers)

           {

                 if($er.Assembly -eq $Assembly)

                 {

                        Write-Host "Event Receiver with Id[" $er.Id "], Name[" $er.Name "] and Type [" $er.Type "] found in [" $ERContainer.Url $ERContainer.DefaultViewUrl "]."

                        if($ReportOnly -eq $false)

                        {

                    Write-Host "Try to delete the receiver:"   

                    $er.Delete()

                    Write-Host "ER deleted."

                        }

                 }

           }

    }

     

     

    After you save this script in a PS1 file and import it (Example: Import-Module .\MissingEV.PS1), you can use the function in the following way:

     

    Delete-MissingAssembly -ContentDb WSS_Content -Assembly "My.Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cfc9a4dcd383ae1e" -ReportOnly

     

    And the output could be:

     

     

    As you can see the output of the Power Shell shows the Id, Name, Type and location of the specific event Receiver, you can decide if remove it with this script or access through PS or a 3rd tool to remove it.

     

    Hope this helped you in the typically Missing server side dependencies issue in the Health Analyzer.