Thursday, March 29, 2012

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

I faced this problem while deploying an event receiver from Visual Studio 2010.  I searched and found that I had made two mistakes.

No1.  No more than Magical ….

Deploying a feature through Visual Studio 2010 kill the vssphost4.exe process first…

clip_image002

No2. I added an Event Receiver to a new Visual Studio010 project.  It was of type ItemDeleting and 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 couldn’t find at first. So pop open your “ItemDeleting” file in solution explorer – Double-click the Elements.xml file.  I saw something like this:

<?xml version="1.0" encoding="utf-8"?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <Receivers ListTemplateId="100" >

      <Receiver>

        <Name>EventReceiver1ItemDeleting</Name>

        <Type>ItemDeleting</Type>

        <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>

        <Class>ListDeleteEventReceiver.ListItemDeleteER.ListItemDeleteER</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.

 

If you have a more elegant solution – please post a comment… I’ll be happy to hear.

...HaPpY CoDiNg

Partha (Aurum)

No comments:

Post a Comment