title: How to attach Event Receiver to SPList programmatically?
body: <p>I'm working on a project i SharePoint 2010 where I have several under sites. each under site contain a list with news and I want to attach an Event Receiver to those lists.</p>
  
  <p>The under sites and lists are created programmatically but I cannot attach the Event Receiver I have in my VS2010 Solution.</p>
  
  <p>I've tried with this:</p>
  
  <pre><code>SPList list = new SPSite(siteURL).OpenWeb().Lists[listName]; 
  SPEventReceiverDefinitionCollection eventReceivers = list.EventReceivers;
  
  SPEventReceiverDefinition eventReceiver = eventReceivers.Add();
  eventReceiver.Name = receiverName;
  eventReceiver.Synchronization = SPEventReceiverSynchronization.Synchronous; 
  eventReceiver.Type = SPEventReceiverType.ItemAdded;
  eventReceiver.SequenceNumber = sequenceNumber; 
  eventReceiver.Assembly = assemblyFullName;
  eventReceiver.Class = assemblyClassName;
  eventReceiver.Data = receiverData;
  
  eventReceiver.Update();
  </code></pre>
  
  <p>But it does not work.</p>
  
  <p>The error message is "Could not load file or assembly 'Projekt_Test1\, \, Version\=1.0.1777.23493\, Culture\=neutral\, PublicKeyToken\=49c7547d535382ab' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)"</p>
  
  <p>Thanks for help.</p>