Fix “MissingAssembly” Errors of Test-SPContentDatabase in SharePoint 2013 Migration

Problem:
During SharePoint 2013 migration, we ran the Test-SPContentDatabase cmdlet, and the output report contains several MissingAssembly errors!

Category        : MissingAssembly
Error           : True
UpgradeBlocking : False
Message         : Assembly [DealEventEventhandler, Version=1.2.6.0, Culture=neutral, PublicKeyToken=b4122bae67581526] is referenced in the database [wss_content], but is not installed on the current farm. Please install any feature/solution which contains this assembly.
Remedy          : One or more assemblies are referenced in the database [wss_content], but are not installed on the current farm. Please install any feature or solution which contains these assemblies.

Fix "MissingAssembly" Errors of Test-SPContentDatabase in SharePoint 2013 Migration

Root Cause:
Usually, the MissingAssembly errors arise on event receivers that are not installed & deployed to the farm and still referenced in the SharePoint list or libraries!

Solution:

Install the missing feature/solution which contains the missing assembly to your SharePoint Farm! Simple, Huh? But wait, You may not always be in a position to do this, and you may proceed to find and remove the missing assemblies from SharePoint at times.

Find all locations where the missing assembly is being referenced and remove using PowerShell:

Let’s use PowerShell to find all places where a particular assembly is being used and remove it. The assembly could be as part of SharePoint event receivers. Set the configuration parameters in the script from Test-SPContentDatabase results.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function Run-SQLScript($SQLServer, $SQLDatabase, $SQLQuery)
{
    $ConnectionString = "Server =" + $SQLServer + "; Database =" + $SQLDatabase + "; Integrated Security = True"
    $Connection = new-object system.data.SqlClient.SQLConnection($ConnectionString)
    $Command = new-object system.data.sqlclient.sqlcommand($SQLQuery,$Connection)
    $Connection.Open()
    $Adapter = New-Object System.Data.sqlclient.sqlDataAdapter $Command
    $Dataset = New-Object System.Data.DataSet
    $Adapter.Fill($Dataset) 
    $Connection.Close()
    $Dataset.Tables[0]
}

#Define configuration parameters
$Server="Abj-SQL-001"
$Database="WSS_Content_KM"
$AssemblyInfo="DealEventHandler, Version=1.2.6.0, Culture=neutral, PublicKeyToken=d256f51c842671b3"           

#Query SQL Server content Database to get information about the MissingAssembly
$Query = "SELECT distinct Id, SiteId, WebId, HostId, HostType from EventReceivers where Assembly = '"+$AssemblyInfo+"'"
$QueryResults = Run-SQLScript -SQLServer $Server -SQLDatabase $Database -SQLQuery $Query # | select Id, Name, SiteId, WebId, HostId, HostType

#Iterate through results
foreach ($Result in $QueryResults)
{
    if($Result.id -ne $Null)
    {
        #Get the location where the event receiver is referred
        if ($Result.HostType -eq 0) #Site Event Receiver
        {
            $Site = Get-SPSite -Limit all | where {$_.Id -eq $Result.SiteId}
            $EventReceiver = $Site.EventReceivers | where {$_.Id -eq $Result.Id}
            #To Delete the Event Receiver
            #$EventReceiver.Delete()
            write-host "Site Event Receivers Found at $($Site.URL)" -foregroundcolor green
        }
        if ($Result.HostType -eq 1) #Web Event Receiver
        {
            $Site = Get-SPSite -Limit all | where {$_.Id -eq $Result.SiteId}
            $Web = $Site | Get-SPWeb -Limit all | where { $_.Id -eq $Result.WebId }
            $EventReceiver = $Web.EventReceivers | where {$_.Id -eq $Result.Id}
            #To Delete the Event Receiver
            #$EventReceiver.Delete()
            write-host "Web Event Receivers Found at $($web.URL)" -foregroundcolor green
        }
        if ($Result.HostType -eq 2) #List Event Receiver
        {
            $Site = Get-SPSite -Limit all | where {$_.Id -eq $Result.SiteId}
            $Web = $Site | Get-SPWeb -Limit all | where { $_.Id -eq $Result.WebId }
            $List = $web.Lists | where {$_.Id -eq $Result.HostId}
            $EventReceiver = $List.EventReceivers | where {$_.Id -eq $Result.Id}
            #To Delete the Event Receiver
            #$EventReceiver.Delete()
            write-host "List Event Receivers Found at $($web.url)/$($List.RootFolder.Url)" -foregroundcolor green
        }
    }
} 

This script finds all locations where the particular assembly is referenced. Uncomment the EventReceiver.delete() line to delete the event receiver.

Here is another post to resolve Assembly missing error in SharePoint 2010 to SharePoint 2013 migration Fix “Missing Event Receivers” issue in SharePoint Migration

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

3 thoughts on “Fix “MissingAssembly” Errors of Test-SPContentDatabase in SharePoint 2013 Migration

  • I’ve tried to use this in a upgrade 2016 to 2019 but this message are showed:
    You cannot call a method on a null-valued expression.
    At line:55 char:13
    $EventReceiver.Delete()
    ~~~~~~~~~~~~~~~~~~~~~~~
    CategoryInfo : InvalidOperation: (:) [], RuntimeException
    FullyQualifiedErrorId : InvokeMethodOnNull

    List Event Receivers Found at /

    Reply
  • Thanks a bunch! I googled millions of these solutions, and this one finally worked 🙂

    Reply
  • Excellent. This helped me very much. Thanks.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *