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();

                      });
                }
            }

1 Answer 1

0

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

10
  • 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
    Commented Jan 14, 2020 at 14:15
  • Before enabling the feature, GAC the dll App_GlobalResources and then execute the powershell command Commented Jan 14, 2020 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
    Commented Jan 14, 2020 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 Commented Jan 14, 2020 at 16:19
  • 1
    It will not be in your sp solution, search in the c drive in SharePoint server Commented Jan 15, 2020 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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