Sue Hernandez's SharePoint Blog

SharePoint and Related Stuff

Error occurred in deployment step ‘Activate Features’: Operation is not valid due to the current state of the object

SharePoint 2010 and Visual Studio 2010.

I added an Event Receiver to a new Visual Studio 2010 project.  Very simple.  It was of type EmailReceived but I don’t think that matters in this case.  I went to deploy the project and got the following error message:

“Error occurred in deployment step ‘Activate Features’: Operation is not valid due to the current state of the object”

Apparently reading up on many people’s posts this can be many things.  Turns out mine was because I did something so normal:  I renamed the namespace and the class name of the class.  Well apparently when I did that, I got out of sync with the automatically generated Elements.xml – which I couldnt’ find at first.

So pop open your “EventReceiver1” file in solution explorer – expand the files underneath it by pressing the + sign.  Double-click the Elements.xml file.  You will see something like this:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   <Receivers ListTemplateId="101">
      <Receiver>
         <Name>
EventReceiver1EmailReceived</Name>
         <Type>EmailReceived</Type>
         <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
         <Class>YourProjectNameHere.EventReceiver1.EventReceiver1</Class>
         <SequenceNumber>10000</SequenceNumber>
      </Receiver>
   </Receivers>
</Elements>

My problem was the <Class> element.  I had renamed my namespace to MyNamespace and my project to MyProjectName.  So my class should have been MyNamespace.MyProjectName.  That was it.

Easy

25 responses to “Error occurred in deployment step ‘Activate Features’: Operation is not valid due to the current state of the object

  1. AMG September 20, 2011 at 11:15 am

    Great, tsx! Save my time a lot!

  2. sayitfst October 10, 2011 at 8:18 pm

    Thank You!!!

  3. Jon October 25, 2011 at 3:25 pm

    Thanks for this post. Saved some time!

  4. chungtran November 3, 2011 at 4:39 am

    Thanks! It’s help me a lot.

  5. Lori January 25, 2012 at 3:10 pm

    Great post — thank you!!

  6. Alejandro February 6, 2012 at 1:06 pm

    This was my problem too, thanks!

  7. Sachira March 11, 2012 at 9:02 am

    Great one. Thanks. Saved lots of time

  8. Mohamed Ramadan March 25, 2012 at 10:04 am

    Too many thanks. It solved my problem

  9. Rashmi April 2, 2012 at 12:05 pm

    Thank you for the post. It solved my problem too.

  10. Abdul-Rahman May 9, 2012 at 4:35 am

    Thanks a lot 🙂

  11. bkwdesign May 11, 2012 at 3:54 pm

    that was it for me, too! I’ve seen this before in my work, but, it had been a while and I forgot. Thanks for the reminder!!!

  12. Bob June 13, 2012 at 8:13 pm

    THANKS!! Exaclty the same problem

  13. Marcos Sánchez July 16, 2012 at 4:10 pm

    Thanks again!!!

  14. gunjan September 10, 2012 at 2:47 am

    Thanks a lot..The same problem i also faced today and the cause behind that..

  15. Guy February 5, 2013 at 7:27 pm

    That did it! Thanks.

  16. Mahesh February 28, 2013 at 4:05 pm

    Thanks. Saved lot of time.

  17. Kurt April 9, 2013 at 1:12 pm

    Thanks a lot, I renamed the namespace as well, and couldn’t figure it out.

  18. arul April 25, 2013 at 4:02 am

    Tks , its solved my issue.

  19. Robert May 30, 2013 at 2:02 pm

    for me it was that after I switched my project from “all CPU” to X86. I got that error, even if I switched back. had to close the project and delete the “obj” folder.

  20. Mike October 9, 2013 at 7:35 pm

    This old post saved me…! Thanks!

  21. daverstuart February 12, 2014 at 2:41 pm

    Thanks Sue! Helped me out big time too!

  22. nooby September 29, 2015 at 9:55 am

    Thanks, you saved me there i was considering to recreate the whole project =/

Leave a reply to Guy Cancel reply