0

There is a problem with Enable-SPFeature command in case of having an event receiver in the feature. Feature Activated event is not fired. If I enable the feature manually everything works well. So, there is a workaround for this :

workaroud

In my case, the feature is scope: WEB

$web= Get-SPWeb -Site https://aaa.com

        $feature = Get-SPFeature "Guid" 
            if($feature)
            {
                $featureId = $feature.Id;
                $site = Get-SPSite $site.Url
                if(-not $web.Features[$featureId])
                {
                    $web.Features.Add($featureId);
                }
            }

error:

Exception calling "Add" with "1" argument(s): "Could not load file or assembly 'App_GlobalResources' or one of its dependencies. The system cannot find the file specified."

So any idea how can I fire the event receiver.

event receiver:

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
            {
 //get ressource value 
            ResourceManager MyResourceClass = new ResourceManager("Resources.MySite.Global", System.Reflection.Assembly.Load("App_GlobalResources"));
            string title= MyResourceClass.GetString("UserControl_Message_Title");
            string Message = MyResourceClass.GetString("UserControl_Message_Description");

using (SPWeb oWeb = properties.Feature.Parent as SPWeb)
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate
                      {
                          SPList oList = oWeb.Lists["splist"];

                          SPListItem oListItem = oList.Items.Add();
                          oListItem["Title"] = title;
                          oListItem["Message"] = msg;

                          oListItem.Update();

                      });
                }
            }
0

Is your feature assembly GACed? If not, make sure the feature assembly is located someplace where powershell can find it.

  • at the feature properties the "receiver Assembly :$SharePoint.Project.AssemblyFullName$" already, any idea how can i added, ow can i make powershell know it ? – Imen Turki Jan 14 at 14:15
  • Before enabling the feature, GAC the dll App_GlobalResources and then execute the powershell command – Karthik Jaganathan Jan 14 at 14:17
  • the wsp is installed whith "-GACDeployment" , i checked the feature under the templates/feature , i found it. but when i nuild the solution i only found dll of wsp and not dll App_GlobalResources – Imen Turki Jan 14 at 16:03
  • Does your code uses httpcontext?? Because when you deploy from UI, httpcontext will be there but the same will not be available in powershell activation – Karthik Jaganathan Jan 14 at 16:19
  • 1
    It will not be in your sp solution, search in the c drive in SharePoint server – Karthik Jaganathan Jan 15 at 16:11

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.