Reputation: 305
I have a SharePoint 2013 solution project (built in VS2013) that contains a feature set to WebApplication level with an event receiver that has no code at all (just for testing purposes).
When I set the feature's Activate On Default property to true and deploy it, The feature seems to have been activated but the ULS shows me the following error (I replaced the actual assembly/file names with dots):
ArgumentException: Failed to load receiver assembly ".................." for feature "......................" (ID: 5e6fc154-bc0d-4768-a558-8d4d8227d92e).: System.IO.FileNotFoundException: Could not load file or assembly '.................' or one of its dependencies. The system cannot find the file specified.
And when I try to deactivate it I get the same error. When I set Activate On Default property to false, then I get the same error when I try to activate it manually.
I have tried the following without success:
Restarted IIS and the timer service
Set the Assembly Deployment Target property of the project to both WebApplication and GlobalAssemblyCache
All I want to do is deploy my feature at web application level and get the event receiver to run and be able to successfully activate/deactivate the feature.
I would very much appreciate your help with this.
Regards
Upvotes: 1
Views: 1977
Reputation: 305
I managed to fix my problem.
After doing a lot of research I learned that if a Web Application-level feature contains an event receiver, then that assembly must be deployed to GAC. This will however cause SharePoint to deploy the wsp package globally. But I wanted to deploy the package to a specific web application. So I went to the package design window, went to the Advanced tab, added the assembly to the package by selecting the "Add Assembly from Project Output" option, entered its details and selected the "GlobalAssemblyCache" option. Finally, I selected the project and in its properties window set the "Include Assembly In Package" property to False. (If you don't do this VS will throw an error when compiling)
This caused SharePoint to deploy the package to my web application automatically via VS (or it will ask you to select a web application when deployed via Central Admin UI).
Surprisingly, it still gave me the same error (failed to load receiver assembly...). But after a retract, cleaning and another deployment, it worked! (sometimes, you might have to do extra things like restarting the SharePoint timer service, restarting IIS, closing and opening VS, or event rebooting to get this to work)
Thanks to everyone who posted a comment to my question.
Upvotes: 1