5

I have a problem when activating a Site scoped feature. Every time I try to activate the solution with STSADM or Powershell I get this error:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN>STSA
DM.EXE -o activatefeature -url http://example.sp2012.com -id aad760ac-22ff-4873-
acb3-b5b727de032d

Failed to load receiver assembly "Customer.Example.Homepages_v1, Version=1.0.0
.0, Culture=neutral, PublicKeyToken=00eb5deafe22c91f" for feature "Customer.Exam
ple.Homepages_v1" (ID: aad760ac-22ff-4873-acb3-b5b727de032d).: System.IO.F
ileNotFoundException: Could not load file or assembly 'Customer.Example.Homepage
s_v1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=00eb5deafe22c91f' or on
e of its dependencies. The system cannot find the file specified.
File name: 'Customer.Example.Homepages_v1, Version=1.0.0.0, Culture=neutral, P
ublicKeyToken=00eb5deafe22c91f'
   at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase,
Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boo
lean throwOnFileNotFound, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence
 assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence as
semblySecurity, 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\M
icrosoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure lo
gging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fus
ion!EnableLog].

The Assembly Deployment Target is set to WebApplication an when i deploy it with Visual Studio 2010 everything works fine, but when i do it manual with the console i get the error?

Is this feature receiver in the same assembly as other parts of my solution?

10
  • What permissions do you have when running PowerShell? You need to be Farm Admin, Local admin (if adding solutions), run Shell as administrator (if UAC is enabled) and for some commands Shell Admin -all depending on what you do in your feature receiver. Also no reasons really to use STSADM, so use PowerShell Commented Oct 22, 2012 at 8:26
  • I have Administrator permissions when running Powershell. But got still the same error message: PS C:\Users\Administrator> Enable-SPFeature -Identity aad760ac-22ff-4873- acb3-b5b727de032d -url example.sp2012.com Enable-SPFeature : Failed to load receiver assembly "Customer.Example.Homepages_v1, Version=1.0.0.0, Culture=neutral,...
    – spry
    Commented Oct 22, 2012 at 8:35
  • I don't get it, the assembly is there: C:\inetpub\wwwroot\wss\VirtualDirectories\example.sp2012.com80\bin\Customer.Example.Homepages_v1.dll
    – spry
    Commented Oct 22, 2012 at 8:38
  • .Net isn't looking in that directory unless it's current or you're running as part of that webapp Commented Oct 22, 2012 at 9:23
  • As Per say, event and feature receivers need to be deployed to a fully trusted location, so it wont make any difference that your file is present in a partial trusted location like bin. Commented Oct 22, 2012 at 11:07

2 Answers 2

7

If the assembly contains any event or feature receivers then the deployment target should be Global Assembly Cache. And if you deploy the solution using a command line then you should start a new instance of that before activating the feature (this is most important when you get to upgrading) as an old version of the dll can't be unloaded.

4
  • Should be, because it's not possible? But why can visual studio deploy the feature with deployment target "webapplication"?
    – spry
    Commented Oct 22, 2012 at 8:42
  • I don't know how VS is doing it, but I think it makes it's activation call from code running in the webapp, or it may load the dll itself. You may use the hack of running Enable-SPFeature while the current directory is the bin-folder of a web app with the solution deployed Commented Oct 22, 2012 at 9:21
  • Thanks for your support, now everything works after i deployed it in the gac and restart my powershell!
    – spry
    Commented Oct 23, 2012 at 11:54
  • I rebooted the machine and tried activating the feature via 'SharePoint 2013 Management Shell' ran as an Administrator. Worked for me!!
    – Muhammedh
    Commented May 5, 2015 at 14:55
9
  1. Remove feature receiver
  2. Clean solution
  3. Close Visual Studio
  4. Delete SharePoint project's obj folder in Windows Explorer
  5. Delete SharePoint project's bin folder in Windows Explorer
  6. Open Visual Studio and re-add feature receiver
  7. Start Debugging
2
  • 1
    Doing 4,5 + restart solved my problem!
    – XristosK
    Commented Feb 27, 2015 at 16:19
  • 1
    @XristosK + Always Force Install on all features since OP's exception was thrown in the middle of deployment process. Commented Jun 18, 2019 at 8:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.