FeatureReceivers needs GAC

On many websites you read about installing FeatureReceiver assembly inside the Global Assembly Cache (GAC) instead of placing the assembly inside you’re web application bin folder. In this post I will explain why it is necessary to use the GAC.

Inside a SharePoint webapplication on site collection level or site level you can activate and deactivate features. If you activate a feature in this context and you’re assembly is located in the web application bin folder everything will be fine. The assembly can be found because you’re inside the context of you’re web application that has the dll (in the bin folder). The .Net framework checks the GAC first, when the assembly cannot be found in the GAC, the local bin folder is checked. So the assembly can be found in this situation.

But when you decide to activate you’re feature from STSADM command or you’re feature will be activated by another site definition feature which contains FeatureActivation dependency, the feature will be activated from within the Central Admin by creating a site collection. In both scenarios the context is different. So the .Net framework checks the GAC first and will find no assembly in the GAC. After the GAC the local bin folder (from stsadm or Central Admin web application) is checkedĀ andĀ the assembly cannot be found there. Because the assembly resides in the bin folder of you’re web application.

This is the message you get:
System.IO.FileNotFoundException: Could not load file or assembly '<assembly>' or one of its dependencies. The system cannot find the file specified.

SOLUTION:
Put all you’re FeatureReceiver assemblies in the GAC.

Leave a Reply