ERROR: Failed to create feature receiver...

I was working on a STSDev project which deployed a feature with a feature receiver. I had the feature working without the FeatureReceiver but as soon as I added the FeatureReceiver related attributes to my <Feature> element I got the following error:

Failed to create feature receiver object from assembly "Org.Project.Solution, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c632353d405b3209", type "Org.Project.Solution.MyFeature.FeatureReceiver" for feature 6a9b2358-ea4e-486d-a4e4-4f813c52ce88: System.ArgumentNullException: Value cannot be null.
Parameter name: type
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject()

After much digging around I discovered that STSDEV's Solution config file refers to a namespace as well as the dll. My FeatureReceiver's namespace was not prefixed with the right namespace

So just be sure that your project conforms to the following:

SolutionName (default name of outputted assembly): Org.Project.Solution (Org.Project.Solution.dll)
FeatureName: MyFeature
FeatureRecieverName: FeatureReceiver (in FeatureReceiver.cs)

Feature Namespace: Org.Project.Solution.MyFeature
SolutionConfig.xml's SafeControl's Namespace Attrib: Org.Project.Solution
Feature.xml's <Feature> ReceiverClass Attribute: Org.Project.Solution.MyFeature.FeatureReceiver
Feature.xml's <Feature> ReceiverAssembly Attribute: Org.Project.Solution

Comments

Anonymous said…
Thank you Paul. That just saved me many hours.
Anonymous said…
OH man this was a HUGE help!!!!! Thanks a bunch WOOT!!!
Anonymous said…
I am getting the exact same error when I try to activate the feature on MySite.
What code, or what file, do I need to change, to prevent this error from appearing?

I just don't fully understand how you got it working.

Thanks,

Dan
Dan said…
I get the exact same error message, when I try to activate the feature on MySite.

What file/code do i need to change to overcome this error message?

Regards,

Dan
Paul said…
Dan, does it only happen on mysite (i.e. it works on regular sites)?

This post describes this problem happening when working with STSDEV, if you are not using STSDEV there could be a few problems. Make sure your feature receiver's namespace is the same namespace specified in the feature.xml file and in the manifest.xml file.
Ryan said…
Paul, you mention that the receiver's namespace needs to be the same namespace specified in the feature.xml file and in the manifest.xml file. I'm a little confused as to what you're saying here. What namespace in the feature.xml and manifest.xml are you referring to?

Thanks,
Ryan
Paul said…
Paul, you mention that the receiver's namespace needs to be the same namespace specified in the feature.xml file and in the manifest.xml file. I'm a little confused as to what you're saying here. What namespace in the feature.xml and manifest.xml are you referring to?

Ryan,

When you want to add a feature reciever to a feature you need to have a 'ReceiverAssembly' attribute on your 'feature' element in your feature.xml file. In addiiton, when you are using STSDEV a manifest.xml file is made for you automatically. If you open this file you'll see that there is a reference to your assembly in there as well. If you change your project name, namespace (or class name) of your receiver class, or add a feature receiver in later you might mess this up and get the error listed above.

By checking that all these are in agreement you might be able to solve your problem if you get the 'Failed to create feature receiver' error.
Anonymous said…
This post is the gift that keeps on giving. Thanks for the help, this information was exactly what I needed.
Anonymous said…
This post dont resolve my error. :(
Anonymous said…
Another SOLUTION (its work for me) :
1) Uninstall assembly from the GAC (gacutil /u )
2) DEPLOY your project.
Anonymous said…
This is good post...
but I got the same problem but mine is different...
CArefully lookat "FeatureReceiver" name both feature.xml and your class name !!
FeatureReciever vs FetureReceiver
see receiver spelleing...i mispelled in feature.xml


Hope it helps someone.....
Michael said…
Thank you so much. This post really saved me time and frustration!
Philip Izod said…
Hey man, thanks for this post. Seems obvious now after looking at the syntax but wasnt the case before hand. Cheers for making the note.

Popular posts from this blog

Microsoft Virtualilzation Headaches

Programmatically Update Page Layouts