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.
Comments
Anonymous
January 01, 2003
The comment has been removedAnonymous
July 18, 2013
Great information on MissingAssembly Error in Health Analyzer--the most common issues in the Health Analyzer when you deploy custom solutions in your SharePoint 2010 environment, Regards , doctors <a href="immediatecarenaperville.com/urgent-care">Urgent care Naperville</a>Anonymous
March 25, 2014
The comment has been removedAnonymous
July 21, 2014
Couldn't get deletion to work with either ForEach or For. So I used the pipeline to grab the ID for each matching assembly and then deleted them by ID.
$evenReceiverIds = $ERContainer.EventReceivers | ? { $.Assembly -like $Assembly } | % { $.ID }
$evenReceiverIds | % {
$er = $ERContainer.EventReceivers[$_]
Write-Host Deleting $er.Assembly, $er.Class, $er.Type
if($ReportOnly -eq $false)
{
$er.Delete()
Write-Host " --[DELETED]"
}
}