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

Great, tsx! Save my time a lot!
Comment by AMG — September 20, 2011 @ 11:15 am
Thank You!!!
Comment by sayitfst — October 10, 2011 @ 8:18 pm
Thanks for this post. Saved some time!
Comment by Jon — October 25, 2011 @ 3:25 pm
Thanks! It’s help me a lot.
Comment by chungtran — November 3, 2011 @ 4:39 am
Thanks !
Comment by suchon — November 27, 2011 @ 4:49 am
Great post — thank you!!
Comment by Lori — January 25, 2012 @ 3:10 pm
This was my problem too, thanks!
Comment by Alejandro — February 6, 2012 @ 1:06 pm
Great one. Thanks. Saved lots of time
Comment by Sachira — March 11, 2012 @ 9:02 am
Too many thanks. It solved my problem
Comment by Mohamed Ramadan — March 25, 2012 @ 10:04 am
Thank you for the post. It solved my problem too.
Comment by Rashmi — April 2, 2012 @ 12:05 pm
Thanks a lot
Comment by Abdul-Rahman — May 9, 2012 @ 4:35 am
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!!!
Comment by bkwdesign — May 11, 2012 @ 3:54 pm
Reblogged this on Truongconglong's Blog.
Comment by truongconglong — May 12, 2012 @ 9:25 am