Remove a missing Claims Provider from the SharePoint configuration database

Currently I am developing a custom claims provider that connects to an identity store in the backend to verify user names from the people picker (ADFS scenario).
One day the search stopped working and I checked the ULS logs to find the cause of the problem. The ULS log was full with errors of this type:

 STS Call: Failed to issue new security token. Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Customer.ClaimsProvider.LDAP, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9512c55e4a68ef80' or one of its dependencies. The system cannot find the file specified. File name: 'Customer.ClaimsProvider.LDAP, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9512c55e4a68ef80'

SharePoint was right, I retracted the claims provider the other day. I redeployed the claims provider to check if that solves the problem but it doesn't, the error was still written to the ULS log. So I started PowerShell to get more information.

I executed the following cmdlets to get a reference to the claim provider manager and list the registerd claim providers:

 $manager = Get-SPClaimProviderManager
$manager.ClaimProviders
 DisplayName : System
 Description : Provides system claim data.
 IsEnabled : True
 IsUsedByDefault : True
 IsVisible : True
 AssemblyName : Microsoft.SharePoint, Version=15.0.0.0,
 Culture=neutral, PublicKeyToken=71e9bce111e9429c
 TypeName : Microsoft.SharePoint.Administration.Claims.SPSyst
 emClaimProvider
 ClaimProvider : Microsoft.SharePoint.Administration.Claims.SPSyst
 emClaimProvider
 ClaimProviderType : Microsoft.SharePoint.Administration.Claims.SPSyst
 emClaimProvider
 IsValid : True
 UpgradedPersistedProperties : {}
 DisplayName : Active Directory
 Description : Active Directory claim data.
 IsEnabled : True
 IsUsedByDefault : False
 IsVisible : True
 AssemblyName : Microsoft.SharePoint, Version=15.0.0.0,
 Culture=neutral, PublicKeyToken=71e9bce111e9429c
 TypeName : Microsoft.SharePoint.Administration.Claims.SPActi
 veDirectoryClaimProvider
 ClaimProvider : Microsoft.SharePoint.Administration.Claims.SPActi
 veDirectoryClaimProvider
 ClaimProviderType : Microsoft.SharePoint.Administration.Claims.SPActi
 veDirectoryClaimProvider
 IsValid : True
 UpgradedPersistedProperties : {}
 DisplayName : All Users
 Description : Provides identity provider claim data.
 IsEnabled : True
 IsUsedByDefault : True
 IsVisible : True
 AssemblyName : Microsoft.SharePoint, Version=15.0.0.0,
 Culture=neutral, PublicKeyToken=71e9bce111e9429c
 TypeName : Microsoft.SharePoint.Administration.Claims.SPAllU
 serClaimProvider
 ClaimProvider : Microsoft.SharePoint.Administration.Claims.SPAllU
 serClaimProvider
 ClaimProviderType : Microsoft.SharePoint.Administration.Claims.SPAllU
 serClaimProvider
 IsValid : True
 UpgradedPersistedProperties : {}
 DisplayName : Forms Auth
 Description : Forms Based Authentication claim data.
 IsEnabled : True
 IsUsedByDefault : False
 IsVisible : True
 AssemblyName : Microsoft.SharePoint, Version=15.0.0.0,
 Culture=neutral, PublicKeyToken=71e9bce111e9429c
 TypeName : Microsoft.SharePoint.Administration.Claims.SPForm
 sClaimProvider
 ClaimProvider : Microsoft.SharePoint.Administration.Claims.SPForm
 sClaimProvider
 ClaimProviderType : Microsoft.SharePoint.Administration.Claims.SPForm
 sClaimProvider
 IsValid : True
 UpgradedPersistedProperties : {}
 DisplayName : User Profile Claim Provider
 Description : User Profile Claim Provider
 IsEnabled : True
 IsUsedByDefault : True
 IsVisible : True
 AssemblyName : Microsoft.Office.Server.UserProfiles,
 Version=15.0.0.0, Culture=neutral,
 PublicKeyToken=71e9bce111e9429c
 TypeName : Microsoft.Office.Server.Security.UserProfileClaim
 Provider
 ClaimProvider : Microsoft.Office.Server.Security.UserProfileClaim
 Provider
 ClaimProviderType : Microsoft.Office.Server.Security.UserProfileClaim
 Provider
 IsValid : True
 UpgradedPersistedProperties : {}
 DisplayName : Customer Ldap
 Description : Claims Provider for getting claims from
 REST-Service with CustomerLdap-Source.
 IsEnabled : True
 IsUsedByDefault : True
 IsVisible : True
 AssemblyName : Customer.ClaimsProvider.LDAP,
 Version=1.0.0.0, Culture=neutral,
 PublicKeyToken=9512c55e4a68ef80
 TypeName : Customer.ClaimsProvider.LDAP.CustomerProvider
 ClaimProvider :
 ClaimProviderType :
 IsValid :
 UpgradedPersistedProperties : {}

The last entry in the list was the wrong one, it shouldn't be there anymore. I checked the methods of the Claim Provider manager object an there was a one with the name "RemoveAt". The method needs the number of the item in the array to remove, in this case it was number 5 (it can be another number in your environment). I used the following command to remove the missing claim provider from the manager:

 $manager.ClaimProviders.RemoveAt(5)

I finally saved the change with the following command:

 $manager.Update()

That solved the problem, the error disapperead from the ULS log and the SharePoint search was working again.