5

I've got a problem where I can enable a feature the UI and everything works as expected through site settings, but if I try and enable the feature via the Sharepoint powershell (which we are doing as part of a scripted deployment), I get the following:

Enable-SPFeature : Failed to create receiver object from assembly "xxxxx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=967e6960f5af91e6 ", class "xxxxx.EventReceiver" for feature "xxxxx.Public.Search" (ID: 026d7c45-a359-4550-822d-1a6c35e58e0 d).: System.ArgumentNullException: Value cannot be null. Parameter name: type

Does anyone know why this would occur, or some things I should check? The feature definition is definitely correct (since deploying it through the UI works as expected, and I've also double checked the PublicKeyToken is correct etc etc), and restarting the services and iisreset doesn't enable me to use Enable-SPFeature either.

Henry C
  • 4,781
  • 4
  • 43
  • 83
  • I have the same problem. I can activate without errors the feature from web UI but not from PowerShell with enable-spfeature. This is also true for all the features scoped at site level with new attached event receivers (without any code inside the events) and assembly deployment target set to webapplication. –  Nov 04 '10 at 10:03

5 Answers5

8

I have the same issue. The curious thing is when you open up a new SP2010 powershell window and reissue the same command the assembly is found without any problems. See: http://khurramdotnet.blogspot.com/2011/01/enable-spfeature-command-throwing.html

Evert
  • 162
  • 2
  • 7
  • 1
    the fact that it works when you open a new PowerShell Window it's because the AppDomain is refreshed with the new (newly upgraded) assemblies! – GillouX Jan 16 '12 at 16:26
1

Try this: http://geoffwebbercross.blogspot.ca/2011/06/failed-to-create-receiver-object-from.html It worked for me, I did not have to change a stitch in my code / solution

  • According to http://stackoverflow.com/help/how-to-answer, you could improve your answer by "[quoting] the most relevant part of an important link" – gturri Jan 25 '14 at 07:57
1

Try this: go to the Control Panel, click on "Programs", click on "Programs and Features", select "Microsoft SharePoint Server 2010" (or whatever you have installed), click "Change", select "Repair" and click "Continue". This is what helped me.

Sven
  • 11
  • 1
0

I had this yesterday, turns out the feature name and the feature receiver name werent matching. To resolve it I copied the FeatureActivated code into notepad (entire code block) or whichever events it is you have coded.

  1. Copy the entire event code that you have written I.e. the FeatureActivated method (including signature)
  2. Remove the EventReceiver from your project.
  3. Add a new event received to your project (you can double check the name for changes)
  4. Paste the Event code back into the event receiver.

I use the following code to deploy using powershell

    if(($Solution -ne $null) -and ($Solution.ContainsWebApplicationResource))
    {
        if ($FeatureScope -eq "Web")
        {
            Install-SPSolution $SolutionName -url $siteUrl -GACDeployment -Confirm:$false
        }
        else
        {
            Install-SPSolution $SolutionName -AllWebApplications -GACDeployment -Confirm:$false
        }
    }
    else
    {
        Install-SPSolution $SolutionName -GACDeployment -Confirm:$false
    }
    while($Solution.Deployed-eq$false)
    {
        Start-Sleep 2
        Write-Host "." -NoNewline
    }
Mauro
  • 4,531
  • 3
  • 30
  • 56
  • I tried this, and it didn't work - I'm pretty sure the event receiver class name is correct, since it works fine when attempting to deploy it through the UI but just not through Powershell... – Henry C Sep 16 '10 at 23:48
0

Don't use the "normal" PowerShell, use the SharePoint 2010 Management Shell instead.

twicky87
  • 1
  • 1