Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Unable to instantiate event handler

  Asked By: Alexandria    Date: Apr 03    Category: Sharepoint    Views: 1151

Iam just trying out some examples with the sharepoint event handler.
I first created a simple assembly that wrote to eventviewer based on
event triggers from sharepoint library. Used identity impersonation,
deployed strong named assemblyto GAC, recycled my app pool etc
etc...everything worked fine until... I extended my code to copy the
doc that created that event to another document library. At this
point it gave me the following error :

Unable to instantiate event handler (assembly "ClsEventHandler,
Version=, Culture=Neutral,PublicKeyToken=ba6f9d9f366145d2",
class "ClsEventHandler.NamespaceEventHandler.ClsEventHandler"), or
report event for "EventHandlerTestLibrary/work.doc" in
"EventHandlerTestLibrary". Cannot complete this action.

My app pool is running under the network service account.



6 Answers Found

Answer #1    Answered By: Ciara Collier     Answered On: Apr 03

I got that error  when I tried code  that accessed the lists.asmx service  in
my handler. How are you trying to copy  the document?

Answer #2    Answered By: Keenan Whitehead     Answered On: Apr 03

By using the CopyTo method. Here is the portion of code

Dim SPWeb As SPWeb = listEvent.Site.OpenWeb()
Dim SPEvItem As SPFile = SPWeb.GetFile(listEvent.UrlAfter)
Dim SPItem As SPListItem = SPEvItem.Item
Dim SPFName As String = SPItem.File.Name.ToString()
Dim wic As WindowsImpersonationContext = CreateIdentity
("", "", "").Impersonate()
If listEvent.Type = SPEvItem.Insert Then
Dim CopyToPath As String = "Backup/" + SPFName

Answer #3    Answered By: Peter Peterson     Answered On: Apr 03

Is the Backup/ library  on the same site? have you looked at the samples in
the wsssdk?

Answer #4    Answered By: Damon Garner     Answered On: Apr 03

yes "backup" doc  lib is in the same site. I did look at the samples
on msdn, any other examples/ suggestions would be welcome...

What could be the possible reasons for this error?

Answer #5    Answered By: Christop Mcfadden     Answered On: Apr 03

Here is what I use for my handler  that fires when an item is inserted in a
form library:

Public Sub OnEvent(ByVal listEvent As Microsoft.SharePoint.SPListEvent)
Implements Microsoft.SharePoint.IListEventSink.OnEvent

On Error Resume Next

Dim SharePointWeb As SPWeb = listEvent.Site.OpenWeb()

Dim SharePointEventItem As SPFile =

Dim oItem As SPListItem = SharePointEventItem.Item

Dim oField As SPField

Dim oFields As SPFieldCollection

Dim SPEvItem As SPFile = SPWeb.GetFile (listEvent.UrlAfter)


'Check to make sure that we actually have the event  item!

If SharePointEventItem Is Nothing Then

EventLog.WriteEntry("Facilities Event Log ", "Cannot retrieve event item",
EventLogEntryType.Information, listEvent.Type)

Exit Sub

End If

'Get the fields collection for the Event Item

oFields = oItem.Fields

'The delete event carries no useful information to log in the fields

If (Len(listEvent.UrlAfter.ToString) > 1) Then

'Event Id Explanation

' -1 : Invalid

' 0 : Insert

' 1 : Update

' 2 : Delete()

' 3 : Move or Rename

' 4 : Copy

' 5 : CheckIn

' 6 : CheckOut

' 7 : UnCheckOut

'Write out the collected information to the Application Log

'EventLog.WriteEntry("Event Log Test", sLog, EventLogEntryType.Information,

'This is just some sample code  that shows how to operate on the different

' event types.

Select Case listEvent.Type

Case SPListEventType.CheckIn

'Perform necessary actions for the CheckIn event

Case SPListEventType.CheckOut

'Perform necessary actions for the CheckOut event

Case SPListEventType.Copy

'Perform necessary actions for the Copy event

Case SPListEventType.Delete

'Perform necessary actions for the Delete event

Case SPListEventType.Insert

'Perform necessary actions for the Insert event

Here is where I would try:

Dim CopyToPath As String = SharePointWeb.Url & "Backup/"


Answer #6    Answered By: Harshita Padwal     Answered On: Apr 03

The best example I've seen for an event  sink is the MSDN recycle bin:

I prefer my approach to deleted documents, but this is a great primer
for moving documents from library  to library.

Didn't find what you were looking for? Find more on Unable to instantiate event handler Or get search suggestion and latest updates.