2

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.

Edit after questions:

I created a very simple SharePoint application in VS2013. I just added a feature, added an event receiver to the feature (with no code), set the feature to WebApplication level and its Activate On Default property to False. Then set the project's Assembly Deployment Target to WebApplication.

Then I deployed the feature (in VS) and tried to activate it in central admin. I still got the same issue. I then retracted the project, set the project's Assembly Deployment Target to GAC and tried again and still got the same error.

I'm just wondering what the right approach is for deploying a feature at web application level so that its event receiver can run and you can activate/deactivate it properly.

  • 1
    Have you issued -GACDeployment while deploying the solution? – Marco Nov 12 '13 at 12:31
  • Serv, I don't know what you mean by that. I deploy the solution in VS and I have tried both WebApplication and GAC. Please read my comments. – seemorgh Nov 13 '13 at 17:16
3

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.

0

The exception reports a failure "loading receiver assembly", so it means that SharePoint raised an error while trying to instantiate the class used as event receiver by the feature. That explains why the "deploy" error disappears when you remove the "Activate On Default" flag: SharePoint is failing when activating the feature, not when deploying the solution!

That said, you need now to discover why the receiver isn't found. I see two main possibilities:

  • somehow, the assembly isn't available. Assuming you opted for Gac deployment, ensure the gac contains the expected version of the assembly. Sometime while developing I notice that a dll may become locked by some random process and thus break the update process.

  • check that the feature points to the right assembly. Do you have changed something in the properties of the feature that may have resulted in a wrong fully qualified name begin used for the receiver? does all the data match?

I would start with this two basic checks. Feel free to report back your result - I will try to provide some more assistance if you can give some more detail.

  • SPArchaeologist, I was going to answer your comment by adding comments is a bit of a hassle here. Please see my answer above. – seemorgh Nov 13 '13 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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