I have a set of event receivers for a SharePoint 2010 content type and Library. Previously, these would install and automatically be activated when I ran a script to install the wsp solution. I dug up a different way of doing this, however, and now they will install appropriately when I run the solution in debug mode in Visual Studio, but they will not install when I run the aforementioned power shell script. I checked the site and made sure the feature was activated, but after doing that I still did not see the event receivers using SPM.
I was following the guide from this page
Event Receiver Elements.xml:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers ListTemplateId="101">
<Receiver>
<Name>EventReceiverItemCheckedIn</Name>
<Type>ItemCheckedIn</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>SharePointFeatures.EventReceiver.EventReceiver</Class>
<SequenceNumber>1000</SequenceNumber>
</Receiver>
<Receiver>
<Name>EventReceiverItemCheckingIn</Name>
<Type>ItemCheckingIn</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>SharePointFeatures.EventReceiver.EventReceiver</Class>
<SequenceNumber>1001</SequenceNumber>
</Receiver>
<Receiver>
<Name>EventReceiverItemUpdated</Name>
<Type>ItemUpdated</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>SharePointFeatures.EventReceiver.EventReceiver</Class>
<SequenceNumber>1002</SequenceNumber>
</Receiver>
<Receiver>
<Name>EventReceiverItemUpdating</Name>
<Type>ItemUpdating</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>harePointFeatures.EventReceiver.EventReceiver</Class>
<SequenceNumber>1003</SequenceNumber>
</Receiver>
<Receiver>
<Name>EventReceiverItemDeleting</Name>
<Type>ItemDeleting</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>SharePointFeatures.EventReceiver.EventReceiver</Class>
<SequenceNumber>1004</SequenceNumber>
</Receiver>
</Receivers>
</Elements>
Feature template.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/">
<Properties>
<Property Key="GloballyAvailable" Value="true"/>
<Property Key="AssemblyQualifiedName" Value="$SharePoint.Type.800d2e40-4c00-4517-9ff4-d11da11b6826.AssemblyQualifiedName$"/>
<Property Key="AssemblyFullName" Value="$SharePoint.Project.AssemblyFullName$"/>
</Properties>
</Feature>
Feature Receiver code:
[Guid("fbe26e13-dba2-4fe6-b947-9f2c34accd39")]
public class FeaturesEventReceiver : SPFeatureReceiver
{
private string EventReceiverClassName;
private string AssemblyFullName;
/// <summary>
/// Feature activated logic
/// </summary>
/// <param name="properties"></param>
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
try
{
SPWeb web = properties.Feature.Parent as SPWeb;
//di-associate EventReceiver from Print only content type
SetAssemblyParams(properties.Feature.Properties);
DisableEventReceiver(web);
//associate EventReceiver to content type as defined in configuration <activefields sharepointcontenttypename="Print Only">
FmiMetadataMappingHandler mappingHandler = WebConfigurationManager.OpenWebConfiguration("/", web.Site.WebApplication.Name).GetSection(Utils.GetConfigSectionNameForWeb(web)) as FmiMetadataMappingHandler;
SPContentType ct = web.ContentTypes[mappingHandler.ActiveFields.SharepointContentTypeName];
if (ct != null)
{
SPEventReceiverDefinition def = ct.EventReceivers.Add();
def.Name = "EventReceiverItemCheckingIn";
def.Type = SPEventReceiverType.ItemCheckingIn;
def.SequenceNumber = 1000;
def.Assembly = AssemblyFullName;
def.Class = EventReceiverClassName;
def.Update();
// bind event receiver to ItemCheckedIn Event
def = ct.EventReceivers.Add();
def.Name = "EventReceiverItemCheckedIn";
def.Type = SPEventReceiverType.ItemCheckedIn;
def.SequenceNumber = 1001;
def.Assembly = AssemblyFullName;
def.Class = EventReceiverClassName;
def.Update();
// bind event receiver to ItemUpdated Event
def = ct.EventReceivers.Add();
def.Name = "EventReceiverItemUpdated";
def.Type = SPEventReceiverType.ItemUpdated;
def.SequenceNumber = 1002;
def.Assembly = AssemblyFullName;
def.Class = EventReceiverClassName;
def.Update();
// bind event receiver to ItemUpdating Event
def = ct.EventReceivers.Add();
def.Name = "EventReceiverItemUpdating";
def.Type = SPEventReceiverType.ItemUpdating;
def.SequenceNumber = 1003;
def.Assembly = AssemblyFullName;
def.Class = EventReceiverClassName;
def.Update();
// bind event receiver to ItemDeleting Event
def = ct.EventReceivers.Add();
def.Name = "CWTEventReceiverItemDeleting";
def.Type = SPEventReceiverType.ItemDeleting;
def.SequenceNumber = 1004;
def.Assembly = AssemblyFullName;
def.Class = EventReceiverClassName;
def.Update();
//update content type with event receiver
ct.Update(true);
Utils.LogMessage("CWT Feature Event Receivers added successfully.");
}
}
catch (Exception ex)
{
Utils.LogError(ex.Message, ex.StackTrace);
}
}
private void SetAssemblyParams(SPFeaturePropertyCollection properties)
{
EventReceiverClassName = properties["AssemblyQualifiedName"].Value;
AssemblyFullName = properties["AssemblyFullName"].Value;
}// end SetAssemblyParams
/// <summary>
/// feature deactivating
/// </summary>
/// <param name="properties"></param>
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SetAssemblyParams(properties.Feature.Properties);
DisableEventReceiver(properties.Feature.Parent as SPWeb);
}
/// <summary>
/// di-associate event receiver from content type
/// </summary>
/// <param name="web"></param>
private void DisableEventReceiver(SPWeb web)
{
try
{
FmiMetadataMappingHandler mappingHandler = WebConfigurationManager.OpenWebConfiguration("/", web.Site.WebApplication.Name).GetSection(Utils.GetConfigSectionNameForWeb(web)) as FmiMetadataMappingHandler;
SPContentType ct = web.ContentTypes[mappingHandler.ActiveFields.SharepointContentTypeName];
string errMsg = string.Empty;
if (ct == null)
{
errMsg = string.Format("{0} has not been created in web {1} ", mappingHandler.ActiveFields.SharepointContentTypeName, web.Title);
Utils.LogError(errMsg);
throw new Exception(errMsg);
}
if (ct != null)
{
SPEventReceiverDefinition[] fmiEvents = new SPEventReceiverDefinition[ct.EventReceivers.Count];
ct.EventReceivers.CopyTo(fmiEvents, 0);
for (int i = 0; i < fmiEvents.Length; i++)
{
if (fmiEvents[i].Class.Equals(EventReceiverClassName, StringComparison.CurrentCultureIgnoreCase))
{
fmiEvents[i].Delete();
Utils.LogError("cwt receiver removed");
}
}
ct.Update(true);
// web.Update();
}
}
catch (Exception ex)
{
Utils.LogError(ex.Message);
}
}
* UPDATE *
So, now it won't install at all, even in debug mode. I looked in the logs and the feature is generating an error during the "FeatureActivated" part of the installation. I commented out all of the code in FeatureActivated and everything except a try/catch in FeatureDeactivating and it still throws this error.
Error message: Type names passed to Assembly.GetType() must not specify an assembly.