SharePoint feature event receiver not firing

sharepoint-2010

I want to add a custom RoleDefinition to my sharepoint site, in VS2010 I added a new feature receiver and under the Activated Event I added this code:

using (SPSite site = new SPSite("http://localhost:8280"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    web.RoleDefinitions.Add(AdminRole);
                    web.Close();
                 }
                site.Close();

            }

Using the package designer I added the feature and from VS I deploy the solution to the "Web" scope. when I go to site features I do see my feature being Active but the Role Definition is not there. I suspect the Event receiver code not being fired so I added some code that writes to a log file and there the file was empty so the code is never reached. knowing that the solution is deployed as a sandbox solution on SharePoint 2010.

any ideas?

Many thanks

Best Answer

The Event receiver did not fire because it was not linked to the feature...doh! here is the thing, in the feature template file these two attributes must be added: ReceiverAssembly="Full name, version, neutral,publikeytoken" ReceiverClass="*Namesapace.classname"

hth

Related Topic