kwizcom banner advertisement

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

Problem:
During SharePoint 2013 migration, we ran 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 arises on event receiver which 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 be always in a position to do this. You may proceed find and removing the missing assemblies from SharePoint at times.

Find all locations where the missing assembly is being referenced and remove using PowerShell:
Lets 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. Un-comment the EventReceiver.delete() line to delete the event receiver.

Here is my another post to resolve Assembly missing error in SharePoint 2010 to SharePoint 2013 migration Fix "Missing Event Receivers" issue in SharePoint Migration
Fix "MissingAssembly" Errors of Test-SPContentDatabase in SharePoint 2013 Migration Fix "MissingAssembly" Errors of Test-SPContentDatabase in SharePoint 2013 Migration Reviewed by Salaudeen Rajack on January 19, 2016 Rating: 5

2 comments:

  1. Excellent. This helped me very much. Thanks.

    ReplyDelete
  2. Thanks a bunch! I googled millions of these solutions, and this one finally worked :)

    ReplyDelete

Please Login and comment to get your questions answered!

Powered by Blogger.