Thursday, 17 October 2013

C# The Handle is Invalid

I have been given a task to debug a SharePoint event receiver as it wasn't doing what was meant to do, so I started by looking at event viewer logs. 

Event viewer error didn't helped much other then saying;

Error loading and running event receiver **Assembly Details**. Additional information is below.
: The handle is invalid

Searched google lot but couldn't find anything relevant in SharePoint context, but somehow figured out, this error "The handle is invalid" comes up when user doesn't have enough permissions to perform a task and in my case it was when event receiver tried to create a new event log or even when try to write a log to already created event log.

Fixed the issue by putting code within   SPSecurity.RunWithElevatedPrivileges(delegate(){  }); block, however couldn't figure out which exact permission was required to let user to write event logs but adding above fixed the issue for me, so all good.

No comments:

Post a Comment