I got this error "Error occurred in deployment step 'Activate Features': Operation is not valid due to the current state of the object " while attaching a event reciver using Visual Studio 2010 in SharePoint. Just for some more information I am attaching the event receiver to a SharePoint 2010 publishing web site. And the event was WebProvisioned.
When I checked the web.config file I have added the Assembly as MyPageLayoutEventReceiver. Though this is same as the assembly name, but was throughing error.
When I change the Assembly name to $SharePoint.Project.AssemblyFullName$, that worked. So my elements.xm file will be as like below:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers >
<Receiver>
<Name>EventReceiver1WebAdding</Name>
<Type>WebAdding</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>MyEventReceiverLayout.EventReceiver1.EventReceiver1</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
<Receiver>
<Name>EventReceiver1WebProvisioned</Name>
<Type>WebProvisioned</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>MyEventReceiverLayout.EventReceiver1.EventReceiver1</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
</Receivers>
</Elements>
When I checked the web.config file I have added the Assembly as MyPageLayoutEventReceiver. Though this is same as the assembly name, but was throughing error.
When I change the Assembly name to $SharePoint.Project.AssemblyFullName$, that worked. So my elements.xm file will be as like below:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers >
<Receiver>
<Name>EventReceiver1WebAdding</Name>
<Type>WebAdding</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>MyEventReceiverLayout.EventReceiver1.EventReceiver1</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
<Receiver>
<Name>EventReceiver1WebProvisioned</Name>
<Type>WebProvisioned</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>MyEventReceiverLayout.EventReceiver1.EventReceiver1</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
</Receivers>
</Elements>
0 on: "Error occurred in deployment step 'Activate Features': Operation is not valid due to the current state of the object"