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

  • Question

  • I'm using Visual Studio 2010 and I am currently working on a SharePoint project with 3 items:
    - List Definition
    - Visual WebPart
    - EventReceiver


    Everything went fine until I added a new event to the EventReceiver. I modified the Elements.xml of the EventReceiver and overwrote the corresponding method.
    Then I deployed my solution to SharePoint via Visual Studio (like many many times before), but the ambiguous error message
    "Error occurred in deployment step 'Activate Features': Operation is not valid due to the current state of the object."
    appeared. (pretty much NOT like many many times before ;)

    I tried to undo my changes, but the error still remains. I even deleted the EventReceiver and added a new (empty) one. Still there.
    In order to check, whether the EventReceiver is really the fault, I excluded the EventReceiver from the feature and the error went away. Now I am wondering how even an empty EventReceiver could cause this error.

    In another thread I read of 3rd party dll's being the problem. I'm using some indeed, but not inside the EventReceiver and they are working fine when the EventReceiver is excluded.

    Does anyone know something that could get me one step forward, because I'm really confused right now.
    Thanks in advance! :)

    Wednesday, January 12, 2011 10:09 AM

Answers

  • Have you checked the scope of the webpart?

    I think that if you try to Activate a Feature or if you add even empty event receivers but for actions that cannot be done, you will have an error.

    For example if you deploy a web part for a farm and you try to activate it from the feature it will not work because you need to activate it from a site, you cannot do it a deployment time and it will give you an error.

    Hope it helps you,

    Nicola.

    • Marked as answer by Urlaubsgimpel Wednesday, January 12, 2011 1:11 PM
    • Unmarked as answer by Urlaubsgimpel Wednesday, January 12, 2011 2:25 PM
    • Marked as answer by Aaron Han - MSFT Tuesday, February 8, 2011 2:55 AM
    Wednesday, January 12, 2011 12:10 PM
  • I definitely think it's related to the scope and to the event receiver in the features, but at this point we should see the code...

    Have you tried to separate the projects? Maybe doing this you will find where is the problem.

    I think it's cleaner if you deploy different packages based on the scope or function they have.

    If they must work togheter have you check the they are activated order? Maybe something is trying to activate a feature before having needed elements deployed of activated.

    For example if you deploy the visual web part that use the your List definition the List definition must be deployed and activated before the web part...

    There is also a feature dependency setting you may check.

    • Marked as answer by Urlaubsgimpel Thursday, January 13, 2011 8:45 AM
    • Unmarked as answer by Urlaubsgimpel Friday, January 14, 2011 9:58 AM
    • Marked as answer by Aaron Han - MSFT Tuesday, February 8, 2011 2:55 AM
    Wednesday, January 12, 2011 3:18 PM

All replies

  • Hmmm,

    Don't mean to sound like the IT Crowd, but have you tried shutting down Visual Studio and opening it back up again? It can get pretty confused at times. Also check for vssphost4.exe. If it's running before you deploy, kill the process in task manager. Lastly, consider an IISRESET.

    Apologies if you've tried all these already! :)

    However, if the EventReceiver is empty, then could you just delete the old EventReceiver and create a new one? A bit of a non-solution, but it might get you on your way quicker.

    Best of luck!


    joel
    Joel's SharePoint Architect Blog
    joelblogs.co.uk
    Want SharePoint Training?
    Wednesday, January 12, 2011 10:23 AM
  • Have you checked the scope of the webpart?

    I think that if you try to Activate a Feature or if you add even empty event receivers but for actions that cannot be done, you will have an error.

    For example if you deploy a web part for a farm and you try to activate it from the feature it will not work because you need to activate it from a site, you cannot do it a deployment time and it will give you an error.

    Hope it helps you,

    Nicola.

    • Marked as answer by Urlaubsgimpel Wednesday, January 12, 2011 1:11 PM
    • Unmarked as answer by Urlaubsgimpel Wednesday, January 12, 2011 2:25 PM
    • Marked as answer by Aaron Han - MSFT Tuesday, February 8, 2011 2:55 AM
    Wednesday, January 12, 2011 12:10 PM
  • Thank you for your replies!

    @Joel:
    Unfortunately, the glorious IT Crowd (:D) method did not work and so did the other advices. I tried them all.
    The EventReceiver is not intended to be empty, I just tested it with an empty EventReceiver to check whether the error occurs because of my code.
    But thank you very much. (Especially for showing me this funny clip, even though I've already seen it a long time ago.)

    @Nicola:
    Thank you! Your post got me in the right direction.

    I solved the problem by making one feature for the list definition and the EventReceiver (Scope: web) and another feature just for the Visual Web Part (Scope: site) and it works fine. :)

    Wednesday, January 12, 2011 1:11 PM
  • Okay. That's strange. I changed absolutely nothing (just added a Cab project to the solution for deployment) and suddently the error is there again. (Even when I remove the cab project and deploy it via VS as before)
    The list definition and the EventReceiver are in one feature (Scope: web) and the visual web part is in another feature (Scope: site).
    Again, if I remove the EventReceiver (from the feature or even completely), the deployment works. Is there anything special I need to keep in mind when deploying EventReceivers?

    Has anyone a clue, what causes this error can have? Would be interesting, because I have no clue at all. It seems so random...

    Thanks :)

    Wednesday, January 12, 2011 2:30 PM
  • I definitely think it's related to the scope and to the event receiver in the features, but at this point we should see the code...

    Have you tried to separate the projects? Maybe doing this you will find where is the problem.

    I think it's cleaner if you deploy different packages based on the scope or function they have.

    If they must work togheter have you check the they are activated order? Maybe something is trying to activate a feature before having needed elements deployed of activated.

    For example if you deploy the visual web part that use the your List definition the List definition must be deployed and activated before the web part...

    There is also a feature dependency setting you may check.

    • Marked as answer by Urlaubsgimpel Thursday, January 13, 2011 8:45 AM
    • Unmarked as answer by Urlaubsgimpel Friday, January 14, 2011 9:58 AM
    • Marked as answer by Aaron Han - MSFT Tuesday, February 8, 2011 2:55 AM
    Wednesday, January 12, 2011 3:18 PM
  • Thank you!

    I had to separate the EventReceiver to another project in order to fix it. Maybe also the fact that I used an "EventReceiver Project" for this new project set something for me, which I had forgotten to do manually before.

    I hope the error won't show up again. :)

    Thursday, January 13, 2011 8:45 AM
  • *sigh*

    Here it is again.
    The EventReceiver is in its own project with nothing else in it.

    I discovered a very strange thing. It's not my project's fault, it seems to be Sharepoint:
    I created a new WebApplication with a site collection and the deployment worked.
    As soon as I place an instance of the List Definition (on which the EventReceiver listens on), the error occurs on every deployment process of the EventReceiver.
    When I delete the instance, the error disappears, too.
    When I create an instance after the deployment, the components work fine, but I can't deploy again before removing the instance. I don't get it. >.<

    I also tried killing vssphost4.exe and resetting iis, but nothing helped. Of course I could go on with my work now, but it's a little bit annoying to delete and create an instance everytime I want to test.

    Friday, January 14, 2011 9:58 AM
  • Ok, it's very difficult to understand where you have the problem without the code, my guessings are based on what you write... :-)

    I feel that we solved some problems, but since you are trying different things others problems came up...

    Maybe this time you are deployng from visual studio to a site but you are trying to use the event receiver in another site, I just don't know what you are doing...

    Try to explain in a logical way what you are doing and what you need...

     

    Friday, January 14, 2011 1:18 PM
  • Did you ever resolve this?  I am having the exact same issue.  One additional twist to mine is that Project Server is involved also.

     

    I have an event receiver that I am trying to deploy thru VS.  It gives the error that was being described here.  I can activate the feature manually though and it works, so I know it's not a problem with the assembly or class name being wrong in the elements file.

     

    It wouldn't be a big deal then except project server chokes when it tries to create the custom site template that has that event receiver defined and it has the same error message.

     

    I have tried putting it in it's own solution, in with other items.  I have killed the process mentioned in this thread.  I have tried list item event receivers and then the site provisioned web receiver and non of them work.  

     

    I may try to sacrifice something to SharePoint gods next.


    - John
    Thursday, June 9, 2011 5:16 PM
  • Thanks, Joel, i have the same problem, and i killed the vssphost4.exe and then deploy, it works now.
    Friday, September 23, 2011 5:36 AM
  • I spend almost 9 hourse to figure out what happend. This kind of message also appears when you have wrong List Url in Receivers. 

    <Receivers ListUrl="--- check if this url is ok ---">
    <Receiver>
      <Name>EventReceiver1</Name>

    Tuesday, October 15, 2013 7:39 PM
  • I had similar issue. This happens when you create Event Receiver based on template and decided to rename class your elements feature not going to synch up with new class name namespace.

    Try chaging class abd assembly names in your new elements.xml, you should be fine

    If you are using web scope then manually activate feature and try to see the log files


    Venkatesam Miriyapalli

    Friday, December 13, 2013 3:33 AM