views:

943

answers:

3

Oh SharePoint...

I've built a custom event receiver that just checks for some fields from the list, and changes some of them as needed.

Still, it's throwing this exception:

Unknown SPRequest error occurred. More information: 0x80070005 ERROR: Failed invoking job id {C67EFFCB-607A-4B6A-8C90-60F615FD1878}

Seen that it might be a security issue, and, in another stackoverflow topic I've seen that it may even be because im using the following code:

  SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(siteId))
                {
                    this.DisableEventFiring();
                  // Logic code.
                  // ...
                }
             });

But removing it will need a recompile, and redeploy. Thought it would be better asking to have sure first.

In the production environment, we have two servers, one for the sites, and one for the database. Active directory is also implemented and fully functional. And for what I've checked, all accounts have the "create subsite" permission on Central Administration, as seen in another topic.

So any ideas?

Thanks in advance.

A: 

What about trying to use

this.DisableEventFiring();
try
{
  using (SPSite site = new SPSite(siteId, properties.Site.SystemAccount.UserToken) {

  }
}
finally
{
this.EnableEventFiring();
}

Ofcourse you can't without RunWithElevatedPrivileges if you want to modify some files on filesystem there, but otherwise it may help.

Janis Veinbergs
A: 

Well I don't want to modify files on filesystem.

The actual implementation of this is to create a custom Anual ID.

The Exception that I get on code, I mean, by execution of the code, which is logged is:

Value does not fall within the expected range. at Microsoft.SharePoint.SPFieldCollection.GetField(String strName, Boolean bThrowException) at Microsoft.SharePoint.SPListItem.GetValue(String strName, Boolean bThrowException) at Microsoft.SharePoint.SPListItem.GetValue(String strName) at Microsoft.SharePoint.SPListItem.get_Item(String fieldName) at PMEventReceiver.OmniItemEventReceiver.<>c_DisplayClass3.b_0() at Microsoft.SharePoint.SPSecurity.CodeToRunElevatedWrapper(Object state) at Microsoft.SharePoint.SPSecurity.<>c_DisplayClass4.b_2() at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode) at PMEventReceiver.OmniItemEventReceiver.ItemAdded(SPItemEventProperties properties)

Could that be that maybe it is not capturing the SPsite object correctly? Thanks in advance.

Felipe Fiali
+2  A: 

Problem solved.

After writing logs and exceptions to txt files, and being mislead by the sharepoint log, What was really happening was that a column name was wrong in my code. Since this is a very specific customization, it had some column names literally wrote to the code. One of them had '_' around it, like Column IN THE LIST, IN SHAREPOINT.

But as it goes to SQL, it didn't have the '_'s.

So when you create a list, it registers in SQL the FIRST name of the column. If you change it, it wont be changed on SQL, it will be changed in the list, in SharePoint, but the column name in SQL will still have its original name...

If you already knew that congrats, because that was such a finding for me...

Felipe Fiali
Did you change InternalName of column ?Because you CAN change display name if you wish.
Janis Veinbergs
Well I'd rather dont mess with that. They changed the display name, the internal stills the same... and as it goes to SQL, it's even more messed up. So, I'll just rebuild the EventReceiver, and leave that alone. Thanks for the tipo though.
Felipe Fiali