SharePoint: Enable- and Disable-SPFeature: Failed to load receiver assembly “…” for feature “…”

I developed a farm solution with feature receivers for SharePoint 2013. The assembly deployment target is “WebApplication” (not “GlobalAssemblyCache”)

Development:

  • Farm Solution for SharePoint 2013 (also 2007 and 2010)
  • Assembly Deployment Target: WebApplication
  • Feature Receivers
    • FeatureActivated
    • FeatureDeactivating

Problem:

I got an error message if I tried to enable the feature using PowerShell script. The same issue is also for disabling feature.

Error message:
PS C:\Users\Administrator> Enable-SPFeature -identity “…_RootLandingPage” -URL http://sharepoint2013/organization/navi_Replace 
Enable-SPFeature : Failed to load receiver assembly “….Variations, Version=1.0.0.0, Culture=neutral, PublicKeyToken=…” for feature
“….Variations_RootLandingPage” (ID:…).: System.IO.FileNotFoundException: Could not load file or assembly ‘…Variations, Version=1.0.0.0, Culture=neutral, PublicKeyToken=…’ or one of its dependencies. The system cannot find the file specified. File name: ‘…Variations, Version=1.0.0.0, Culture=neutral, PublicKeyToken=….’ at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName
assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,
Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.Reflection.Assembly.Load(String assemblyString) at
Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject() WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. At line:1 char:1 + Enable-SPFeature -identity “…Variations_RootLandingPage” -URL http://sha …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidData: (Microsoft.Share…etEnableFeature: SPCmdletEnableFeature)
[Enable-SPFeature], ArgumentException
+ FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletEnableFeature

Cause:

The dll-file from the farm solution is not a global assembly, because it deploys to web application. This file is available in the folder for instance: C:\inetpub\wwwroot\wss\VirtualDirectories\80\bin.
By default, PowerShell script looks the DLL-file in the GAC, instead of in the CAS.

Solution:

I think there are two possibilities to solve this issue.

  1. Load right assembly
    I didn’t try it because it loads a DLL-file and is not always on the same path. The script should run in all environments
  2. Use client-side SharePoint API
    Yeah, it works. I only need both DLL-files (Microsoft.SharePoint.Client and Microsoft.SharePoint.Client.Runtime). The PowerShell script can enable and disable the feature. You can copy the code below.
 The code is longer, but it works and it can run also on the client side.
Have a nice day! 🙂

Leave a Reply

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