I followed the steps to create the ApplicationEventReceiver and the console application to deploy the solution, but the console app is throwing an exception. I am guessing it's the way I'm referring to my assembly.
Code:
Unhandled Exception: System.InvalidOperationException: Could not load file or assembly 'ApplicationEventReceiver, Version=1.0.0.0, Culture=neutral' or one of its dependencies. The system cannot find the file specified.
at Microsoft.SharePoint.SPEventReceiverDefinition.ValidAssembly()
at Microsoft.SharePoint.SPEventReceiverDefinition.ValidReceiverFields()
at Microsoft.SharePoint.SPEventReceiverDefinition.UpdateInternal(Boolean isMi
gration)
at Microsoft.SharePoint.SPEventReceiverDefinition.Update()
at Microsoft.SharePoint.SPEventReceiverDefinitionCollection.Add(SPEventReceiv
erType receiverType, String assembly, String className)
at ConsoleApplication3.Program.Main(String[] args) in C:\Documents and Settings\robbert.vanandel\My Documents\Visual Studio 2008\Projects\ConsoleApplication3\Program.cs:line 20
How do I refer the console application to my ApplicationEventReceiver. I have the applicationeventreceiver inside the ApplicationEventReceiver namespace:
Code:
namespace ApplicationEventReceiver
{
class ApplicationEventReceiver : SPItemEventReceiver
and my console application looks like this:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
SPSite site = new SPSite("http://oriontest/hiringmanagement/");
SPWeb web = site.OpenWeb();
SPList list = web.Lists["Applicant"];
string assemblyName = "ApplicationEventReceiver, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6ac52d8504a20881";
string className = "ApplicationEventReceiver.ApplicationEventReceiver";
list.EventReceivers.Add(SPEventReceiverType.ItemAdded, assemblyName, className);
Console.WriteLine(" - Registered - ");
Console.Read();
}
}
}
Your help is appreciated.